/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* !
 * \file unsorted_segment_sum.cpp
 * \brief tiling function of op
 */
#include "unsorted_segment_sum_tiling_rt2.h"
#include "log.h"
#include "graph/types.h"
#include "graph/operator.h"
#include "register/op_tiling_info.h"
#include "register/op_tiling_attr_utils.h"
#include "register/op_impl_registry.h"
#include "exe_graph/runtime/tiling_context.h"
#include "vector_op_info.h"
#include "graph/small_vector.h"
#include "op_tiling.h"
#include "exe_graph/lowering/shape_utils.h"
#include "auto_tiling_rt2.h"
#include "exe_graph/runtime/shape.h"

namespace optilingUss {
using namespace ge;

const size_t INPUT_DATA_IDX = 0;
const size_t INPUT_SEGMENT_IDS_IDX = 1;
const size_t INPUT_NUM_SEGMENTS_IDX = 2;

const std::string UNSORTED_SEGMENT_SUM_OP_TYPE = "UnsortedSegmentSum";
const int32_t BYTE_BLOCK = 32;
const int32_t MIN_ELE_SIZE_USING_ALL_CORE = 1024;
const int32_t MASK_FP32 = 64;
const int32_t MASK_INT32 = 64;
const int32_t MASK_FP16 = 128;
const int32_t MAX_REPEAT_TIME = 255;
const int32_t FP32_ELE_NUM_ALIGN_32B = 8;
const int32_t BYTE_FULL_MASK = 256;
const int32_t MULTI = 4;
const int32_t FP16_BLOCK_NUM = 16;
const int32_t INT32_BLOCK_NUM = 8;
const int32_t INT32_MIN_NUM = -2147483648;
const int32_t EACH_CORE_NUM_UNIT = 64;
const int32_t MASK_NUM_UNIT = 255;

// dtype
const std::string DTYPE_FP32 = "float32";
const std::string DTYPE_FP16 = "float16";
const std::string DTYPE_INT32 = "int32";
const std::string DTYPE_INT8 = "int8";
const std::string DTYPE_UINT8 = "uint8";

// ub tensor num
const int32_t UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_ALIGN = 2;
const int32_t UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_ONE = 6;
const int32_t UB_TENSOR_NUM_FP32_INPUT_ONE_DIM = 3;
const int32_t UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_NOT_ALIGN = 3;
const int32_t UB_TENSOR_NUM_FP32_PAD = 6;
const int32_t PAD_ONCE = 128;
const int32_t PAD_LASE_AXIS = 168;
const int32_t UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_NOT_ALIGN_HP = 3;

// fp32 select key
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_SMALL_E = 1;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ONE = 2;
const int32_t SELECT_KEY_MODE_FP32_INPUT_ONE_DIM = 2;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E = 4;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_BIG_E = 5;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_BIG_E = 6;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ONE_MODIFY = 7;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ONE_MULTI = 8;
const int32_t SELECT_KEY_MODE_FP32_INPUT_NUM_SEGMENT_ONE = 17;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_SMALL_E_HP = 18;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E_HP = 19;
const int32_t SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E_HP_PAD = 20;

// int32 select key
const int32_t SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_SMALL_ID = 9;
const int32_t SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_BIG_ID = 10;
const int32_t SELECT_KEY_MODE_NO_ATOMIC_BIG_E_SMALL_ID = 11;
const int32_t SELECT_KEY_MODE_NO_ATOMIC_BIG_E_BIG_ID = 12;
const int32_t SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_SMALL_ID_SMALLBLOCK = 13;
const int32_t SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_BIG_ID_SMALLBLOCK = 14;
const int32_t SELECT_KEY_MODE_NO_ATOMIC_NUM_SEGMENT_ONE = 15;
const int32_t SELECT_KEY_MODE_NO_ATOMIC_ALL_IN_ALIGN = 16;

const int32_t PARA_CORE_NUM_0 = 0;
const int32_t PARA_UB_SIZE_1 = 1;
const int32_t PARA_UB_TENSOR_NUM_2 = 2;
const int32_t PARA_IMPL_MODE_3 = 3;
const int32_t UB_TENSOR_NUM_2 = 2;
const int32_t UB_TENSOR_MAX_X_NUM = 16000;
const int32_t PART_TWO = 2;
const int32_t PART_THREE = 3;
const int32_t PART_FOUR = 4;
const int32_t PART_FIVE = 5;
const int32_t PART_SIX = 6;
const int32_t PART_SERVERN = 7;


enum EleByte {
    FP16_BYTE = 2,
    FP32_BYTE = 4,
    INT32_BYTE = 4,
    INT64_BYTE = 8,
    INT8_BYTE = 1,
    UINT8_BYTE = 1
};
enum ParamsMode {
    FRONT_CORE = 0,
    LAST_CORE = 1
};
enum InputDataParams {
    FRONT_PART_FRONT_CORE = 0,
    LAST_PART_FRONT_CORE = 1,
    FRONT_PART_LAST_CORE = 2,
    LAST_PART_LAST_CORE = 3
};

struct CommParas {
    int32_t e_num;
    int32_t x_e_num;
    int32_t num_segments;
    int32_t ub_size;
    int32_t impl_mode;
    int32_t ub_tensor_ele_num;
    int32_t ub_tensor_ele_num_pad;
    int32_t e_size_align;
    bool is_pad;
};

struct CommParas4Int32 {
    ge::DataType input_dytpe;
    EleByte ele_byte;
    int32_t e_once_num;
    int32_t all_size;
    int32_t num_segments;
};

struct CommParas4UbSizeNoAtomic {
    ge::DataType input_dtype;
    int32_t ub_size;
    int32_t e_size;
    int32_t output_ub_ele_num_one_row;
    int32_t need_core_num;
    int32_t mask;
    int32_t num_segments;
    int32_t ub_tensor_size_id;
    int32_t ub_tensor_size_input;
    int32_t ub_tensor_size_outpu;
};

struct CommParas4TilingModeNoAtomic {
    ge::DataType input_dtype;
    int32_t e_size;
    int32_t ids_size;
    int32_t ub_tensor_size;
    int32_t ub_tensor_size_input;
    int32_t need_core;
    int32_t output_ub_ele_num_one_row;
    int32_t all_size;
    int32_t num_segments;
};

struct InputParamsGm2UbOut {
    int32_t mode;
    int32_t input_mov_times_gm2ub;
    int32_t input_front_burst_len;
    int32_t input_last_burst_len;
    int32_t input_ele_num_ub_front_part;
    int32_t input_ele_num_ub_last_part;
    int32_t input_rows_front_part;
    int32_t input_rows_last_part;
};

/* *****************COMMON_FUNCTION***************** */
static int32_t ComputeDivRemainders(const int32_t &num, const int32_t &factor, const int32_t &times)
{
    int32_t res = num - factor * times;
    return res;
}

static int32_t UssCeil(const int32_t &num, const int32_t &factor)
{
    if (factor == 0) {
        return num;
    }

    int32_t res = (num % factor == 0) ? num : factor * (num / factor + 1);
    return res;
}

static int32_t UssCeilDiv(const int32_t &num, const int32_t &factor)
{
    if (factor == 0) {
        return num;
    }

    int32_t res = (num % factor == 0) ? num / factor : num / factor + 1;
    return res;
}

static int32_t UssCeilDivNoAtomic(const int32_t &num, const int32_t &factor, const int32_t &e_size,
    const int32_t &output_ub_ele_num_one_row)
{
    int32_t res = 0;

    if (factor == 0) {
        res = num;
    } else {
        res = num / factor;
    }

    if (factor > 1 && e_size < output_ub_ele_num_one_row) {
        if (e_size * res % output_ub_ele_num_one_row != 0) {
            res = res / output_ub_ele_num_one_row * output_ub_ele_num_one_row;
        }
        int32_t last = num - (factor - 1) * res;
        if (e_size * last < output_ub_ele_num_one_row) {
            last = output_ub_ele_num_one_row / e_size + 1;
            res = (num - last) / (factor - 1);
            if (res < 1) {
                res = 1;
            }
            res = e_size * res / output_ub_ele_num_one_row * output_ub_ele_num_one_row / e_size;
        }
    }
    return res;
}

void ComputeDiv(const int32_t &num, const int32_t &factor, int32_t &front_part_num, int32_t &last_part)
{
    front_part_num = num / factor;
    last_part = num - front_part_num * factor;
    return;
}

static bool CheckHighPerf(const int32_t &ub_size, const int32_t &e_size, const int32_t &impl_mode)
{
    int32_t e_size_align8 = UssCeil(e_size, FP32_ELE_NUM_ALIGN_32B);
    int32_t x_ub_size = ub_size / UB_TENSOR_NUM_2 / BYTE_BLOCK * BYTE_BLOCK;
    if ((impl_mode == 1) && (((e_size_align8 * UB_TENSOR_NUM_2 + FP32_ELE_NUM_ALIGN_32B) * FP32_BYTE) < x_ub_size)) {
        return true;
    }
    return false;
}
static bool IsPad(const int32_t &ub_size, const int32_t &e_size, const int32_t &impl_mode)
{
    if (e_size % FP32_ELE_NUM_ALIGN_32B == 0) {
        return false;
    }
    int32_t e_size_align8 = UssCeil(e_size, FP32_ELE_NUM_ALIGN_32B);
    int32_t x_ub_size = ub_size / UB_TENSOR_NUM_FP32_PAD / BYTE_BLOCK * BYTE_BLOCK;
    int32_t num = x_ub_size / MULTI;
    if ((impl_mode == 1) && (e_size < PAD_LASE_AXIS && PAD_ONCE * e_size_align8 < num)) {
        return true;
    }
    return false;
}

static bool GetTilingMode(const CommParas &commParas, const int32_t &x_ub_size, int32_t &selectKey)
{
    int32_t e_num = commParas.e_num;
    int32_t x_e_num = commParas.x_e_num;
    int32_t num_segments = commParas.num_segments;
    int32_t ub_size = commParas.ub_size;
    int32_t x_ub_ele_num = x_ub_size / FP32_BYTE;
    int32_t impl_mode = commParas.impl_mode;
    bool is_pad = commParas.is_pad;

    bool isHighPerf = CheckHighPerf(ub_size, e_num, impl_mode);

    if (num_segments == 1) {
        selectKey = SELECT_KEY_MODE_FP32_INPUT_NUM_SEGMENT_ONE;
        return true;
    }

    if (num_segments > 1 && x_e_num >= 1) {
        if (e_num % FP32_ELE_NUM_ALIGN_32B == 0) {
            if (e_num < x_ub_ele_num) {
                selectKey = isHighPerf ? SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_SMALL_E_HP :
                                         SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_SMALL_E;
                return true;
            }
            selectKey = SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_BIG_E;
            return true;
        }
        if (e_num < x_ub_ele_num) {
            if (isHighPerf && is_pad) {
                selectKey = SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E_HP_PAD;
                return true;
            }
            selectKey = isHighPerf ? SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E_HP :
                                     SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E;
            return true;
        }
        selectKey = SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_BIG_E;
        return true;
    }

    return false;
}

static bool GetTilingModeNoAtomic(const CommParas4TilingModeNoAtomic comm_params, int32_t &select_key,
    int32_t &e_once_num, int32_t &id_once_num, int32_t &num_segment_max)
{
    int input_byte = 0;
    input_byte = (comm_params.input_dtype == ge::DT_FLOAT16) ? FP16_BYTE : FP32_BYTE;

    int32_t e_once_ubsize = (comm_params.ub_tensor_size_input / BYTE_FULL_MASK) * BYTE_FULL_MASK;
    e_once_num = e_once_ubsize / input_byte;
    id_once_num = ((comm_params.ub_tensor_size / BYTE_BLOCK) * BYTE_BLOCK) / INT32_BYTE;
    num_segment_max = ((comm_params.ub_tensor_size / BYTE_BLOCK) * BYTE_BLOCK) / input_byte;
    num_segment_max = num_segment_max / comm_params.e_size;

    if (comm_params.num_segments == 1) {
        select_key = SELECT_KEY_MODE_NO_ATOMIC_NUM_SEGMENT_ONE;

        return true;
    } else if (comm_params.e_size > e_once_num && comm_params.ids_size > id_once_num) {
        // e big id big
        select_key = SELECT_KEY_MODE_NO_ATOMIC_BIG_E_BIG_ID;

        return true;
    } else if (comm_params.e_size > e_once_num && comm_params.ids_size <= id_once_num) {
        // e nig id small
        select_key = SELECT_KEY_MODE_NO_ATOMIC_BIG_E_SMALL_ID;

        return true;
    } else if (comm_params.e_size <= e_once_num && comm_params.ids_size <= id_once_num) {
        // e small id small
        select_key = SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_SMALL_ID;
        if (comm_params.need_core > 1 && comm_params.e_size < comm_params.output_ub_ele_num_one_row) {
            select_key = SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_SMALL_ID_SMALLBLOCK;
        } else if (comm_params.e_size % comm_params.output_ub_ele_num_one_row == 0 &&
            comm_params.all_size < e_once_num) {
            select_key = SELECT_KEY_MODE_NO_ATOMIC_ALL_IN_ALIGN;
        }

        return true;
    } else if (comm_params.ids_size > id_once_num && comm_params.e_size <= e_once_num) {
        // e small id big
        select_key = SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_BIG_ID;
        if (comm_params.need_core > 1 && comm_params.e_size < comm_params.output_ub_ele_num_one_row) {
            select_key = SELECT_KEY_MODE_NO_ATOMIC_SMALL_E_BIG_ID_SMALLBLOCK;
        }

        return true;
    }

    return false;
}

static ge::graphStatus CalcNeededCoreNum(gert::TilingContext *context, const CommParas &commParas,
    const int32_t &ids_size, const int32_t &core_num, int32_t &need_core_num)
{
    CHK_PRT_RET(core_num == 0, HCCL_ERROR("CalcNeededCoreNum check param failed, core_num is 0"), ge::GRAPH_FAILED);
    int32_t ele_num = ids_size / core_num;

    if (commParas.num_segments > 1) {
        if (commParas.e_num > 1) {
            need_core_num = (ele_num >= 1) ? core_num : ids_size;
        } else {
            if (ids_size <= EACH_CORE_NUM_UNIT || ele_num <= 0) {
                need_core_num = 1;
            } else {
                need_core_num = (ele_num >= EACH_CORE_NUM_UNIT) ? core_num : ids_size / EACH_CORE_NUM_UNIT;
            }
        }

        return ge::GRAPH_SUCCESS;
    } else {
        need_core_num = (ele_num >= 1) ? core_num : ids_size;

        return ge::GRAPH_SUCCESS;
    }

    need_core_num = 1;

    return ge::GRAPH_SUCCESS;
}

static ge::graphStatus CalcNeededCoreByNumSegments(gert::TilingContext *context,
    const CommParas4UbSizeNoAtomic comm_ub_size_params, const int32_t &core_num, int32_t &need_core_num)
{
    CHK_PRT_RET(core_num == 0, HCCL_ERROR("CalcNeededCoreByNumSegments check param failed, core_num is 0"),
        ge::GRAPH_FAILED);
    int32_t ele_num = comm_ub_size_params.num_segments / core_num;

    if (comm_ub_size_params.num_segments == 1) {
        if (comm_ub_size_params.e_size <= comm_ub_size_params.output_ub_ele_num_one_row) {
            need_core_num = 1;
        } else {
            CHK_PRT_RET(comm_ub_size_params.output_ub_ele_num_one_row == 0,
                HCCL_ERROR("CalcNeededCoreByNumSegments check param failed, output_ub_ele_num_one_row is 0"),
                ge::GRAPH_FAILED);
            int32_t core_one = comm_ub_size_params.e_size / comm_ub_size_params.output_ub_ele_num_one_row;
            if (core_one >= core_num) {
                need_core_num = core_num;
            } else {
                need_core_num = (comm_ub_size_params.e_size % comm_ub_size_params.output_ub_ele_num_one_row == 0) ?
                    core_one :
                    core_one + 1;
            }
        }

        return ge::GRAPH_SUCCESS;
    }
    if (comm_ub_size_params.e_size < comm_ub_size_params.output_ub_ele_num_one_row &&
        ele_num < comm_ub_size_params.output_ub_ele_num_one_row) {
        need_core_num = 1;

        return ge::GRAPH_SUCCESS;
    }
    if (comm_ub_size_params.e_size >= comm_ub_size_params.output_ub_ele_num_one_row) {
        need_core_num = (ele_num >= 1) ? core_num : comm_ub_size_params.num_segments;

        return ge::GRAPH_SUCCESS;
    }
    if (comm_ub_size_params.e_size < comm_ub_size_params.output_ub_ele_num_one_row &&
        ele_num >= comm_ub_size_params.output_ub_ele_num_one_row) {
        need_core_num = core_num;

        return ge::GRAPH_SUCCESS;
    }

    need_core_num = 1;
    return ge::GRAPH_SUCCESS;
}

static void ComputeUbTensorSizeNoAtomic(const CommParas4UbSizeNoAtomic comm_params, int32_t &ub_tensor_size_id,
    int32_t &ub_tensor_size_input, int32_t &ub_tensor_size_output)
{
    int32_t input_ele_byte = (comm_params.input_dtype == ge::DT_FLOAT16) ? FP16_BYTE : INT32_BYTE;
    if (comm_params.num_segments == 1) {
        ub_tensor_size_id = comm_params.ub_size / UB_TENSOR_NUM_2;
        ub_tensor_size_input = ub_tensor_size_id;
        ub_tensor_size_output = ub_tensor_size_id;
    } else if (comm_params.need_core_num > 1 && comm_params.e_size < comm_params.output_ub_ele_num_one_row) {
        int32_t ub_tensor_num = UB_TENSOR_NUM_2;
        ub_tensor_size_input = comm_params.mask * input_ele_byte;
        ub_tensor_size_id = (comm_params.ub_size - ub_tensor_size_input) / ub_tensor_num;
        ub_tensor_size_output = ub_tensor_size_id;
    } else {
        ub_tensor_size_input = UB_TENSOR_MAX_X_NUM * input_ele_byte;
        ub_tensor_size_output = ub_tensor_size_input;
        ub_tensor_size_id = comm_params.ub_size - UB_TENSOR_NUM_2 * ub_tensor_size_input;
    }

    return;
}

static void NumSegmentOne(const int32_t &max_ele_num_one_ub_tensor, const int32_t &mask, const EleByte &ele_byte,
    const int32_t &mode, UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t e_mov_times_gm2ub_input_scalar = 0;
    int32_t e_ub2gm_front_burst_len_input_scalar = 0;
    int32_t e_ub2gm_last_burst_len_input_scalar = 0;
    int32_t repeat_times_last_part = 0;
    int32_t num_segments_front_core_input_scalar = 0;
    int32_t repeat_time_last_part_input_scalar = 0;

    if (mode == FRONT_CORE) {
        e_mov_times_gm2ub_input_scalar = tiling_params->e_mov_times_gm2ub_input_scalar;
        num_segments_front_core_input_scalar = tiling_params->num_segments_front_core_input_scalar;
    } else {
        e_mov_times_gm2ub_input_scalar = tiling_params->e_mov_times_gm2ub_input_scalar_lastcore;
        num_segments_front_core_input_scalar = tiling_params->num_segments_last_core_input_scalar;
    }

    if (e_mov_times_gm2ub_input_scalar > 1) {
        tiling_params->e_num_front_part_input_scalar = max_ele_num_one_ub_tensor;
        e_ub2gm_front_burst_len_input_scalar =
            UssCeilDiv(tiling_params->e_num_front_part_input_scalar * ele_byte, BYTE_BLOCK);
        tiling_params->repeat_times = UssCeilDiv(tiling_params->e_num_front_part_input_scalar, mask * MASK_NUM_UNIT);

        tiling_params->repeat_time_front_part_input_scalar = UssCeilDiv(tiling_params->e_num_front_part_input_scalar -
            (tiling_params->repeat_times - 1) * mask * MASK_NUM_UNIT,
            mask);

        tiling_params->e_num_last_part_input_scalar = ComputeDivRemainders(num_segments_front_core_input_scalar,
            tiling_params->e_num_front_part_input_scalar, e_mov_times_gm2ub_input_scalar - 1);
        e_ub2gm_last_burst_len_input_scalar =
            UssCeilDiv(tiling_params->e_num_last_part_input_scalar * ele_byte, BYTE_BLOCK);

        repeat_times_last_part = UssCeilDiv(tiling_params->e_num_last_part_input_scalar, mask * MASK_NUM_UNIT);
        if (repeat_times_last_part > 1) {
            repeat_time_last_part_input_scalar = UssCeilDiv(tiling_params->e_num_last_part_input_scalar -
                (repeat_times_last_part - 1) * mask * MASK_NUM_UNIT,
                mask);
        } else {
            repeat_time_last_part_input_scalar = UssCeilDiv(tiling_params->e_num_last_part_input_scalar, mask);
        }
    } else {
        tiling_params->e_num_front_part_input_scalar = num_segments_front_core_input_scalar;

        e_ub2gm_front_burst_len_input_scalar =
            UssCeilDiv(tiling_params->e_num_front_part_input_scalar * ele_byte, BYTE_BLOCK);
        tiling_params->repeat_times = UssCeilDiv(tiling_params->e_num_front_part_input_scalar, mask * MASK_NUM_UNIT);
        if (tiling_params->repeat_times > 1) {
            tiling_params->repeat_time_front_part_input_scalar = UssCeilDiv(
                tiling_params->e_num_front_part_input_scalar - (tiling_params->repeat_times - 1) * mask * MASK_NUM_UNIT,
                mask);
        } else {
            tiling_params->repeat_time_front_part_input_scalar =
                UssCeilDiv(tiling_params->e_num_front_part_input_scalar, mask);
        }
        repeat_time_last_part_input_scalar = tiling_params->repeat_time_front_part_input_scalar;
        tiling_params->e_num_last_part_input_scalar = tiling_params->e_num_front_part_input_scalar;
        e_ub2gm_last_burst_len_input_scalar = e_ub2gm_front_burst_len_input_scalar;
        repeat_times_last_part = tiling_params->repeat_times;
    }

    if (mode == FRONT_CORE) {
        tiling_params->e_ub2gm_front_burst_len_input_scalar = e_ub2gm_front_burst_len_input_scalar;
        tiling_params->e_ub2gm_last_burst_len_input_scalar = e_ub2gm_last_burst_len_input_scalar;
        tiling_params->repeat_times_last_part = repeat_times_last_part;
        tiling_params->repeat_time_last_part_input_scalar = repeat_time_last_part_input_scalar;
    } else {
        tiling_params->e_ub2gm_front_burst_len_input_scalar_lastcore = e_ub2gm_front_burst_len_input_scalar;
        tiling_params->e_ub2gm_last_burst_len_input_scalar_lastcore = e_ub2gm_last_burst_len_input_scalar;
        tiling_params->repeat_times_last_part_lastcore = repeat_times_last_part;
        tiling_params->repeat_time_front_part_input_scalar_lastcore = repeat_time_last_part_input_scalar;
    }

    return;
}

static void ComputeUbTensorSize(CommParas &commParas, int32_t &x_ub_size, int32_t &ids_ub_size, int32_t &x_ub_size_pad)
{
    int32_t e_num = commParas.e_num;
    int32_t num_segments = commParas.num_segments;
    int32_t ub_size = commParas.ub_size;
    int32_t impl_mode = commParas.impl_mode;

    bool isHighPerf = CheckHighPerf(ub_size, e_num, impl_mode);
    commParas.is_pad = IsPad(ub_size, e_num, impl_mode);
    if (num_segments == 1) {
        ids_ub_size = ub_size / BYTE_BLOCK * BYTE_BLOCK;
        x_ub_size = ids_ub_size;
        return;
    }

    int32_t ub_tensor_num = 0;
    int32_t ids_ub_size_perf = 0;
    // align
    if (e_num % FP32_ELE_NUM_ALIGN_32B == 0) {
        ub_tensor_num = UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_ALIGN;
        ids_ub_size = ((ub_size / ub_tensor_num) / BYTE_BLOCK) * BYTE_BLOCK;
        x_ub_size = ids_ub_size;
        ids_ub_size_perf = ((ub_size / UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_ONE) / BYTE_BLOCK) * BYTE_BLOCK;
        if (isHighPerf) {
            x_ub_size = ids_ub_size_perf;
            ids_ub_size = ids_ub_size_perf;
        }
        return;
    }

    // not align
    ub_tensor_num = UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_NOT_ALIGN;
    ids_ub_size = ((ub_size / ub_tensor_num) / BYTE_BLOCK) * BYTE_BLOCK;
    x_ub_size = ids_ub_size;
    if (isHighPerf && commParas.is_pad) {
        ids_ub_size_perf = ((ub_size / UB_TENSOR_NUM_FP32_PAD) / BYTE_BLOCK) * BYTE_BLOCK;
        ids_ub_size = ids_ub_size_perf;
        x_ub_size = ids_ub_size_perf;
        x_ub_size_pad = ids_ub_size_perf;
    }
    if (isHighPerf && (not commParas.is_pad)) {
        ids_ub_size_perf = ((ub_size / UB_TENSOR_NUM_FP32_INPUT_LAST_AXIS_NOT_ALIGN_HP) / BYTE_BLOCK) * BYTE_BLOCK;
        ids_ub_size = ids_ub_size_perf;
        x_ub_size = ids_ub_size_perf;
        x_ub_size_pad = 0;
    }
    return;
}

/* *****************MODE_FP32_INPUT_LAST_AXIS_ALIGN***************** */
static void ComputeEleNumOneCore(const int32_t &min_ele_num, const int32_t &ids_num, const int32_t &e_size,
    const int32_t &num_segments, UnsortedSegmentSumTilingParamsFp32 *tiling_params)
{
    int32_t core_need = tiling_params->need_core_num_input_scalar;
    if (num_segments > 1) {
        tiling_params->ids_ele_num_front_core_input_scalar = (ids_num + core_need - 1) / core_need;

        tiling_params->ids_ele_num_last_core_input_scalar =
            ComputeDivRemainders(ids_num, tiling_params->ids_ele_num_front_core_input_scalar, core_need - 1);
        if (tiling_params->ids_ele_num_last_core_input_scalar <= 0) {
            tiling_params->ids_ele_num_front_core_input_scalar = ids_num / core_need;
            tiling_params->ids_ele_num_last_core_input_scalar =
                ComputeDivRemainders(ids_num, tiling_params->ids_ele_num_front_core_input_scalar, core_need - 1);
        }

        tiling_params->input_ele_num_front_core_input_scalar =
            tiling_params->ids_ele_num_front_core_input_scalar * e_size;
        tiling_params->input_ele_num_last_core_input_scalar =
            tiling_params->ids_ele_num_last_core_input_scalar * e_size;
    } else {
        tiling_params->ids_ele_num_front_core_input_scalar = (ids_num + core_need - 1) / core_need;
        tiling_params->ids_ele_num_last_core_input_scalar =
            ComputeDivRemainders(ids_num, tiling_params->ids_ele_num_front_core_input_scalar, core_need - 1);
        if (tiling_params->ids_ele_num_last_core_input_scalar <= 0) {
            tiling_params->ids_ele_num_front_core_input_scalar = ids_num / core_need;
            tiling_params->ids_ele_num_last_core_input_scalar =
                ComputeDivRemainders(ids_num, tiling_params->ids_ele_num_front_core_input_scalar, core_need - 1);
        }
    }
}

static void SetInputParamsMovGm2ub(InputParamsGm2UbOut &gm_ub_out_params,
    UnsortedSegmentSumTilingParamsFp32 *tiling_params)
{
    if (gm_ub_out_params.mode == FRONT_PART_FRONT_CORE) {
        tiling_params->input_mov_times_gm2ub_front_part_front_core_input_scalar =
            gm_ub_out_params.input_mov_times_gm2ub;
        tiling_params->input_front_burst_len_front_part_front_core_input_scalar =
            gm_ub_out_params.input_front_burst_len;
        tiling_params->input_last_burst_len_front_part_front_core_input_scalar = gm_ub_out_params.input_last_burst_len;
        tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_front_part;
        tiling_params->input_last_ele_num_ub_front_part_front_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_last_part;
        tiling_params->input_front_rows_front_part_front_core_input_scalar = gm_ub_out_params.input_rows_front_part;
        tiling_params->input_last_rows_front_part_front_core_input_scalar = gm_ub_out_params.input_rows_last_part;
    } else if (gm_ub_out_params.mode == LAST_PART_FRONT_CORE) {
        tiling_params->input_mov_times_gm2ub_last_part_front_core_input_scalar = gm_ub_out_params.input_mov_times_gm2ub;
        tiling_params->input_front_burst_len_last_part_front_core_input_scalar = gm_ub_out_params.input_front_burst_len;
        tiling_params->input_last_burst_len_last_part_front_core_input_scalar = gm_ub_out_params.input_last_burst_len;
        tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_front_part;
        tiling_params->input_last_ele_num_ub_last_part_front_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_last_part;
        tiling_params->input_front_rows_last_part_front_core_input_scalar = gm_ub_out_params.input_rows_front_part;
        tiling_params->input_last_rows_last_part_front_core_input_scalar = gm_ub_out_params.input_rows_last_part;
    } else if (gm_ub_out_params.mode == FRONT_PART_LAST_CORE) {
        tiling_params->input_mov_times_gm2ub_front_part_last_core_input_scalar = gm_ub_out_params.input_mov_times_gm2ub;
        tiling_params->input_front_burst_len_front_part_last_core_input_scalar = gm_ub_out_params.input_front_burst_len;
        tiling_params->input_last_burst_len_front_part_last_core_input_scalar = gm_ub_out_params.input_last_burst_len;
        tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_front_part;
        tiling_params->input_last_ele_num_ub_front_part_last_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_last_part;
        tiling_params->input_front_rows_front_part_last_core_input_scalar = gm_ub_out_params.input_rows_front_part;
        tiling_params->input_last_rows_front_part_last_core_input_scalar = gm_ub_out_params.input_rows_last_part;
    } else if (gm_ub_out_params.mode == LAST_PART_LAST_CORE) {
        tiling_params->input_mov_times_gm2ub_last_part_last_core_input_scalar = gm_ub_out_params.input_mov_times_gm2ub;
        tiling_params->input_front_burst_len_last_part_last_core_input_scalar = gm_ub_out_params.input_front_burst_len;
        tiling_params->input_last_burst_len_last_part_last_core_input_scalar = gm_ub_out_params.input_last_burst_len;
        tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_front_part;
        tiling_params->input_last_ele_num_ub_last_part_last_core_input_scalar =
            gm_ub_out_params.input_ele_num_ub_last_part;
        tiling_params->input_front_rows_last_part_last_core_input_scalar = gm_ub_out_params.input_rows_front_part;
        tiling_params->input_last_rows_last_part_last_core_input_scalar = gm_ub_out_params.input_rows_last_part;
    }

    return;
}

static void ComputeInputParamsMovGm2ub(const int32_t &ub_tensor_size, const EleByte &input_ele_byte,
    const int32_t &e_size, UnsortedSegmentSumTilingParamsFp32 *tiling_params, InputParamsGm2UbOut &gm_ub_out_params)
{
    int32_t e_mov_times_gm2ub = 0;
    int32_t ids_ele_num_ub = 0;

    if (gm_ub_out_params.mode == FRONT_PART_FRONT_CORE) {
        e_mov_times_gm2ub = tiling_params->e_mov_times_gm2ub_input_scalar;
        ids_ele_num_ub = tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar;
    } else if (gm_ub_out_params.mode == LAST_PART_FRONT_CORE) {
        e_mov_times_gm2ub = tiling_params->e_mov_times_gm2ub_input_scalar;
        ids_ele_num_ub = tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar;
    } else if (gm_ub_out_params.mode == FRONT_PART_LAST_CORE) {
        e_mov_times_gm2ub = tiling_params->e_mov_times_gm2ub_input_scalar;
        ids_ele_num_ub = tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar;
    } else if (gm_ub_out_params.mode == LAST_PART_LAST_CORE) {
        e_mov_times_gm2ub = tiling_params->e_mov_times_gm2ub_input_scalar;
        ids_ele_num_ub = tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar;
    }

    if (e_mov_times_gm2ub == 1) {
        // e_size is small, ub_tensor_size is enough for e_num
        int32_t e_byte_align_32B = UssCeil(e_size, FP32_ELE_NUM_ALIGN_32B) * input_ele_byte;
        gm_ub_out_params.input_rows_front_part = ub_tensor_size / e_byte_align_32B;
        gm_ub_out_params.input_mov_times_gm2ub = UssCeilDiv(ids_ele_num_ub, gm_ub_out_params.input_rows_front_part);
        if (gm_ub_out_params.input_mov_times_gm2ub > 1) {
            gm_ub_out_params.input_front_burst_len =
                e_byte_align_32B * gm_ub_out_params.input_rows_front_part / BYTE_BLOCK;
            gm_ub_out_params.input_ele_num_ub_front_part = e_size * gm_ub_out_params.input_rows_front_part;
            gm_ub_out_params.input_rows_last_part = ComputeDivRemainders(ids_ele_num_ub,
                gm_ub_out_params.input_rows_front_part, gm_ub_out_params.input_mov_times_gm2ub - 1);
            gm_ub_out_params.input_last_burst_len =
                e_byte_align_32B * gm_ub_out_params.input_rows_last_part / BYTE_BLOCK;
            gm_ub_out_params.input_ele_num_ub_last_part = gm_ub_out_params.input_rows_last_part * e_size;
        } else if (gm_ub_out_params.input_mov_times_gm2ub == 1) {
            gm_ub_out_params.input_rows_front_part = ids_ele_num_ub;
            gm_ub_out_params.input_rows_last_part = gm_ub_out_params.input_rows_front_part;
            gm_ub_out_params.input_ele_num_ub_front_part = e_size * gm_ub_out_params.input_rows_front_part;
            gm_ub_out_params.input_ele_num_ub_last_part = gm_ub_out_params.input_ele_num_ub_front_part;
            gm_ub_out_params.input_front_burst_len =
                UssCeil(gm_ub_out_params.input_ele_num_ub_front_part * input_ele_byte, BYTE_BLOCK) / BYTE_BLOCK;
            gm_ub_out_params.input_last_burst_len = gm_ub_out_params.input_front_burst_len;
        }
    } else if (e_mov_times_gm2ub > 1) {
        // e_size is big, ub_tensor_size is not enough for e_num, use e params to move data
        gm_ub_out_params.input_mov_times_gm2ub = ids_ele_num_ub;
    }
    return;
}

static void ComputeIdsParamsMovGm2ub(const int32_t &ub_tensor_size, const EleByte &ids_ele_byte, const int32_t &mode,
    UnsortedSegmentSumTilingParamsFp32 *tiling_params)
{
    int32_t ids_mov_times_gm2ub = 0;
    int32_t ids_front_burst_len = 0;
    int32_t ids_last_burst_len = 0;
    int32_t ids_ele_num_ub_front_part = 0;
    int32_t ids_ele_num_ub_last_part = 0;
    int32_t max_ids_ele_num_one_ub_tensor = ub_tensor_size / ids_ele_byte;

    int32_t ids_ele_num_one_core = (mode == FRONT_CORE) ? tiling_params->ids_ele_num_front_core_input_scalar :
                                                          tiling_params->ids_ele_num_last_core_input_scalar;
    if (ids_ele_num_one_core <= max_ids_ele_num_one_ub_tensor) {
        // mov_times = 1, ub tensor is enough for ele one core
        ids_mov_times_gm2ub = 1;
        ids_ele_num_ub_front_part = ids_ele_num_one_core;
        ids_ele_num_ub_last_part = ids_ele_num_ub_front_part;
    } else {
        // mov_times > 1
        if (ids_ele_num_one_core % max_ids_ele_num_one_ub_tensor == 0) {
            // no last part
            ids_mov_times_gm2ub = ids_ele_num_one_core / max_ids_ele_num_one_ub_tensor;
            ids_ele_num_ub_front_part = max_ids_ele_num_one_ub_tensor;
            ids_ele_num_ub_last_part = ids_ele_num_ub_front_part;
        } else {
            // exist last part
            ids_mov_times_gm2ub = ids_ele_num_one_core / max_ids_ele_num_one_ub_tensor + 1;
            ids_ele_num_ub_front_part = max_ids_ele_num_one_ub_tensor;
            ids_ele_num_ub_last_part =
                ComputeDivRemainders(ids_ele_num_one_core, max_ids_ele_num_one_ub_tensor, ids_mov_times_gm2ub - 1);
        }
    }

    ids_front_burst_len = UssCeilDiv(ids_ele_num_ub_front_part * ids_ele_byte, BYTE_BLOCK);
    ids_last_burst_len = UssCeilDiv(ids_ele_num_ub_last_part * ids_ele_byte, BYTE_BLOCK);

    if (mode == FRONT_CORE) {
        tiling_params->ids_mov_times_gm2ub_front_core_input_scalar = ids_mov_times_gm2ub;
        tiling_params->ids_front_burst_len_front_core_input_scalar = ids_front_burst_len;
        tiling_params->ids_last_burst_len_front_core_input_scalar = ids_last_burst_len;
        tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar = ids_ele_num_ub_front_part;
        tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar = ids_ele_num_ub_last_part;
    } else {
        tiling_params->ids_mov_times_gm2ub_last_core_input_scalar = ids_mov_times_gm2ub;
        tiling_params->ids_front_burst_len_last_core_input_scalar = ids_front_burst_len;
        tiling_params->ids_last_burst_len_last_core_input_scalar = ids_last_burst_len;
        tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar = ids_ele_num_ub_front_part;
        tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar = ids_ele_num_ub_last_part;
    }

    return;
}

static void ComputeIdsParamsMovGm2ubNoAtomic(const int32_t &ids_ele_num_one_core, const int32_t &id_once_num,
    const EleByte &ids_ele_byte, UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t max_ids_ele_num_one_ub_tensor = id_once_num;
    if (ids_ele_num_one_core <= max_ids_ele_num_one_ub_tensor) {
        // mov_times = 1, ub tensor is enough for ele one core
        tiling_params->ids_mov_times_gm2ub_input_scalar = 1;
        tiling_params->ids_ele_num_ub_front_part_input_scalar = ids_ele_num_one_core;
        tiling_params->ids_ele_num_ub_last_part_input_scalar = tiling_params->ids_ele_num_ub_front_part_input_scalar;
    } else {
        // mov_times > 1
        if (ids_ele_num_one_core % max_ids_ele_num_one_ub_tensor == 0) {
            // no last part
            tiling_params->ids_mov_times_gm2ub_input_scalar = ids_ele_num_one_core / max_ids_ele_num_one_ub_tensor;
            tiling_params->ids_ele_num_ub_front_part_input_scalar = max_ids_ele_num_one_ub_tensor;
            tiling_params->ids_ele_num_ub_last_part_input_scalar =
                tiling_params->ids_ele_num_ub_front_part_input_scalar;
        } else {
            // exist last part
            tiling_params->ids_mov_times_gm2ub_input_scalar = ids_ele_num_one_core / max_ids_ele_num_one_ub_tensor + 1;
            tiling_params->ids_ele_num_ub_front_part_input_scalar = max_ids_ele_num_one_ub_tensor;
            tiling_params->ids_ele_num_ub_last_part_input_scalar = ComputeDivRemainders(ids_ele_num_one_core,
                max_ids_ele_num_one_ub_tensor, tiling_params->ids_mov_times_gm2ub_input_scalar - 1);
        }
    }
    tiling_params->ids_front_burst_len_input_scalar =
        UssCeilDiv(tiling_params->ids_ele_num_ub_front_part_input_scalar * ids_ele_byte, BYTE_BLOCK);
    tiling_params->ids_last_burst_len_input_scalar =
        UssCeilDiv(tiling_params->ids_ele_num_ub_last_part_input_scalar * ids_ele_byte, BYTE_BLOCK);
}
static void ComputeInitOutputUbParams(const int32_t &ids_ele_num, const int32_t &output_ub_ele_num_one_row,
    UnsortedSegmentSumTilingParamsFp32 *tiling_params, int32_t mode)
{
    int32_t e_size_align = tiling_params->input_last_axis_align_floor_ele_num_input_scalar;
    int32_t repeat_times = UssCeilDiv(ids_ele_num * output_ub_ele_num_one_row, MASK_FP32);
    int32_t repeat_pad = ids_ele_num / 128;
    int32_t sheng = ComputeDivRemainders(ids_ele_num, 128, repeat_pad);
    int32_t col_sub_block = UssCeilDiv(sheng * e_size_align, 8);

    int32_t output_ub_init_times = 0;
    int32_t output_ub_init_last_repeat_time = 0;
    HCCL_DEBUG("#e_size_align is %d, ids_ele_num is %d, repeat_pad is %d, sheng is %d, col_sub_block is %d, mode is %d",
        e_size_align, ids_ele_num, repeat_pad, sheng, col_sub_block, mode);
    if (repeat_times % MAX_REPEAT_TIME == 0) {
        output_ub_init_times = repeat_times / MAX_REPEAT_TIME;
        output_ub_init_last_repeat_time = MAX_REPEAT_TIME;
    } else {
        output_ub_init_times = repeat_times / MAX_REPEAT_TIME + 1;
        output_ub_init_last_repeat_time =
            ComputeDivRemainders(repeat_times, repeat_times / MAX_REPEAT_TIME, MAX_REPEAT_TIME);
    }
    if (mode == 0) {
        tiling_params->output_ub_init_last_repeat_time_front_part_front_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_times_front_part_front_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_front_front_part_front_core = repeat_pad;
        tiling_params->col_sub_block_front_front_part_front_core = col_sub_block;
    } else if (mode == 1) {
        tiling_params->output_ub_init_last_row_last_repeat_time_front_part_front_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_last_row_times_front_part_front_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_last_front_part_front_core = repeat_pad;
        tiling_params->col_sub_block_last_front_part_front_core = col_sub_block;
    } else if (mode == PART_TWO) {
        tiling_params->output_ub_init_last_repeat_time_last_part_front_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_times_last_part_front_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_front_last_part_front_core = repeat_pad;
        tiling_params->col_sub_block_front_last_part_front_core = col_sub_block;
    } else if (mode == PART_THREE) {
        tiling_params->output_ub_init_last_row_last_repeat_time_last_part_front_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_last_row_times_last_part_front_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_last_last_part_front_core = repeat_pad;
        tiling_params->col_sub_block_last_last_part_front_core = col_sub_block;
    } else if (mode == PART_FOUR) {
        tiling_params->output_ub_init_last_repeat_time_front_part_last_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_times_front_part_last_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_front_front_part_last_core = repeat_pad;
        tiling_params->col_sub_block_front_front_part_last_core = col_sub_block;
    } else if (mode == PART_FIVE) {
        tiling_params->output_ub_init_last_row_last_repeat_time_front_part_last_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_last_row_times_front_part_last_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_last_front_part_last_core = repeat_pad;
        tiling_params->col_sub_block_last_front_part_last_core = col_sub_block;
    } else if (mode == PART_SIX) {
        tiling_params->output_ub_init_last_repeat_time_last_part_last_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_times_last_part_last_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_front_last_part_last_core = repeat_pad;
        tiling_params->col_sub_block_front_last_part_last_core = col_sub_block;
    } else if (mode == PART_SERVERN) {
        tiling_params->output_ub_init_last_row_last_repeat_time_last_part_last_core_input_scalar =
            output_ub_init_last_repeat_time;
        tiling_params->output_ub_init_last_row_times_last_part_last_core_input_scalar = output_ub_init_times;
        tiling_params->repeat_last_last_part_last_core = repeat_pad;
        tiling_params->col_sub_block_last_last_part_last_core = col_sub_block;
    }
}

static void ComputeNumSegmentsParams(const int32_t &num_segmens, const int32_t &e_size,
    const int32_t &output_ub_ele_num_one_row, UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    if (tiling_params->need_core_num_input_scalar == 1 && num_segmens > 1) {
        tiling_params->num_segments_front_core_input_scalar = num_segmens;
        tiling_params->num_segments_last_core_input_scalar = tiling_params->num_segments_front_core_input_scalar;
    } else if (tiling_params->need_core_num_input_scalar > 1 && num_segmens > 1) {
        tiling_params->num_segments_front_core_input_scalar = UssCeilDivNoAtomic(num_segmens,
            tiling_params->need_core_num_input_scalar, e_size, output_ub_ele_num_one_row);
        tiling_params->num_segments_last_core_input_scalar = ComputeDivRemainders(num_segmens,
            tiling_params->num_segments_front_core_input_scalar, tiling_params->need_core_num_input_scalar - 1);
    } else if (num_segmens == 1) {
        if (e_size < output_ub_ele_num_one_row) {
            tiling_params->num_segments_front_core_input_scalar = e_size;
            tiling_params->num_segments_last_core_input_scalar = e_size;
        } else {
            if (e_size / tiling_params->need_core_num_input_scalar > output_ub_ele_num_one_row) {
                tiling_params->num_segments_front_core_input_scalar = e_size /
                    tiling_params->need_core_num_input_scalar / output_ub_ele_num_one_row * output_ub_ele_num_one_row;
            } else {
                tiling_params->num_segments_front_core_input_scalar = output_ub_ele_num_one_row;
            }
            tiling_params->num_segments_last_core_input_scalar = e_size -
                (tiling_params->num_segments_front_core_input_scalar * (tiling_params->need_core_num_input_scalar - 1));
        }
    }

    return;
}

static void ComputeENumParamsGEMaxEleNum(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t mask = (comm_paras.input_dytpe == ge::DT_INT32) ? MASK_INT32 : MASK_FP16;
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;

    tiling_params->e_mov_times_gm2ub_input_scalar =
        UssCeilDiv(tiling_params->e_num_input_scalar, comm_paras.e_once_num);
    int32_t last = ComputeDivRemainders(tiling_params->e_num_input_scalar, comm_paras.e_once_num,
        tiling_params->e_mov_times_gm2ub_input_scalar - 1);
    if (last < byte) {
        tiling_params->e_mov_times_gm2ub_input_scalar =
            UssCeilDiv(tiling_params->e_num_input_scalar, comm_paras.e_once_num - mask);
    }
    // front part
    tiling_params->e_gm2ub_front_burst_len_input_scalar =
        UssCeilDiv(comm_paras.e_once_num * comm_paras.ele_byte, BYTE_BLOCK);
    tiling_params->e_ub2gm_front_burst_len_input_scalar = comm_paras.e_once_num * comm_paras.ele_byte / BYTE_BLOCK;
    tiling_params->e_num_front_part_input_scalar = comm_paras.e_once_num;
    tiling_params->repeat_time_front_part_input_scalar = UssCeilDiv(tiling_params->e_num_front_part_input_scalar, mask);
    // last part
    tiling_params->e_num_last_part_input_scalar = ComputeDivRemainders(tiling_params->e_num_input_scalar,
        tiling_params->e_num_front_part_input_scalar, tiling_params->e_mov_times_gm2ub_input_scalar - 1);
    tiling_params->e_gm2ub_last_burst_len_input_scalar =
        UssCeilDiv(tiling_params->e_num_last_part_input_scalar * comm_paras.ele_byte, BYTE_BLOCK);
    tiling_params->repeat_time_last_part_input_scalar = UssCeilDiv(tiling_params->e_num_last_part_input_scalar, mask);
    tiling_params->e_ub2gm_last_burst_len_input_scalar =
        tiling_params->e_num_last_part_input_scalar * comm_paras.ele_byte / BYTE_BLOCK;

    return;
}

static void ComputeENumParamsInputScalarGEOneBlockNum(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t mask = (comm_paras.input_dytpe == ge::DT_INT32) ? MASK_INT32 : MASK_FP16;
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;

    tiling_params->e_ub2gm_front_burst_len_input_scalar =
        tiling_params->e_num_input_scalar * comm_paras.ele_byte / BYTE_BLOCK;
    if (tiling_params->need_core_num_input_scalar == 1 &&
        tiling_params->e_num_input_scalar * comm_paras.ele_byte % BYTE_BLOCK != 0) {
        tiling_params->e_ub2gm_front_burst_len_input_scalar = tiling_params->e_ub2gm_front_burst_len_input_scalar + 1;
    }
    tiling_params->e_gm2ub_front_burst_len_input_scalar =
        UssCeilDiv(tiling_params->e_num_input_scalar * comm_paras.ele_byte, BYTE_BLOCK);
    if (tiling_params->e_ub2gm_front_burst_len_input_scalar < 1) {
        tiling_params->e_ub2gm_front_burst_len_input_scalar = 1;
    }
    tiling_params->e_num_front_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->repeat_time_front_part_input_scalar = UssCeilDiv(tiling_params->e_num_front_part_input_scalar, mask);
    // last part
    tiling_params->e_num_last_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_ub2gm_last_burst_len_input_scalar = tiling_params->e_ub2gm_front_burst_len_input_scalar;
    tiling_params->e_gm2ub_last_burst_len_input_scalar = tiling_params->e_gm2ub_front_burst_len_input_scalar;
    if (tiling_params->e_num_input_scalar % byte == 0 && comm_paras.all_size <= comm_paras.e_once_num) {
        tiling_params->e_gm2ub_front_burst_len_input_scalar =
            UssCeilDiv(comm_paras.all_size * comm_paras.ele_byte, BYTE_BLOCK);
        tiling_params->e_gm2ub_last_burst_len_input_scalar = tiling_params->e_gm2ub_front_burst_len_input_scalar;
    }
    tiling_params->repeat_time_last_part_input_scalar = tiling_params->repeat_time_front_part_input_scalar;

    return;
}

static void ComputeENumParamsFrontInputScalarLESegmentMax(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;
    int32_t count = tiling_params->e_num_input_scalar * tiling_params->num_segments_front_core_input_scalar;

    tiling_params->num_segment_max_time = 1;
    tiling_params->e_ub2gm_front_burst_len_input_scalar = count * comm_paras.ele_byte / BYTE_BLOCK;
    if (tiling_params->e_ub2gm_front_burst_len_input_scalar < 1) {
        tiling_params->e_ub2gm_front_burst_len_input_scalar = 1;
    }
    tiling_params->front_num_segment = tiling_params->num_segments_front_core_input_scalar;
    tiling_params->front_num_segment_last = tiling_params->num_segments_front_core_input_scalar;
    tiling_params->e_gm2ub_front_burst_len_input_scalar = 1;
    tiling_params->repeat_time_front_part_input_scalar = 1;
    tiling_params->align_scalar = (count % byte == 0) ? 0 : byte - (count - (count / byte) * byte);
    tiling_params->e_num_front_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_num_last_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_ub2gm_last_burst_len_input_scalar = tiling_params->e_ub2gm_front_burst_len_input_scalar;
    tiling_params->e_gm2ub_last_burst_len_input_scalar = tiling_params->e_gm2ub_front_burst_len_input_scalar;
    tiling_params->repeat_time_last_part_input_scalar = tiling_params->repeat_time_front_part_input_scalar;

    return;
}

static void ComputeENumParamsFrontInputScalarGTSegmentMax(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;

    tiling_params->num_segment_max_time =
        tiling_params->num_segments_front_core_input_scalar / tiling_params->num_segment_max;
    tiling_params->num_segment_max_time =
        (tiling_params->num_segments_front_core_input_scalar % tiling_params->num_segment_max == 0) ?
        tiling_params->num_segment_max_time :
        tiling_params->num_segment_max_time + 1;
    tiling_params->front_num_segment = tiling_params->num_segment_max;
    tiling_params->front_num_segment_last = tiling_params->num_segments_front_core_input_scalar -
        tiling_params->num_segment_max * (tiling_params->num_segment_max_time - 1);
    if (tiling_params->front_num_segment_last * tiling_params->e_num_input_scalar < byte) {
        tiling_params->front_num_segment_last = byte;
        int32_t front = tiling_params->num_segments_front_core_input_scalar - tiling_params->front_num_segment_last;
        tiling_params->num_segment_max = (front / (tiling_params->num_segment_max_time - 1) / byte) * byte;
        tiling_params->front_num_segment = tiling_params->num_segment_max;
        tiling_params->front_num_segment_last = tiling_params->num_segments_front_core_input_scalar -
            tiling_params->num_segment_max * (tiling_params->num_segment_max_time - 1);
    }
    tiling_params->align_scalar =
        (tiling_params->front_num_segment_last * tiling_params->e_num_input_scalar % byte == 0) ?
        0 :
        byte - (tiling_params->front_num_segment_last * tiling_params->e_num_input_scalar -
        (tiling_params->front_num_segment_last * tiling_params->e_num_input_scalar / byte) * byte);
    tiling_params->e_ub2gm_front_burst_len_input_scalar =
        tiling_params->num_segment_max * tiling_params->e_num_input_scalar * comm_paras.ele_byte / BYTE_BLOCK;
    tiling_params->e_gm2ub_front_burst_len_input_scalar = 1;
    tiling_params->repeat_time_front_part_input_scalar = 1;

    tiling_params->e_num_front_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_num_last_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_ub2gm_last_burst_len_input_scalar =
        tiling_params->front_num_segment_last * tiling_params->e_num_input_scalar * comm_paras.ele_byte / BYTE_BLOCK;
    tiling_params->e_gm2ub_last_burst_len_input_scalar = tiling_params->e_gm2ub_front_burst_len_input_scalar;
    tiling_params->repeat_time_last_part_input_scalar = tiling_params->repeat_time_front_part_input_scalar;

    return;
}

static void ComputeENumParamsLastInputScalarLTSegmentMax(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;
    int32_t lastcore_count = tiling_params->e_num_input_scalar * tiling_params->num_segments_last_core_input_scalar;

    tiling_params->num_segment_max_time_lastcore = 1;
    tiling_params->align_scalar_lastcore =
        (lastcore_count % byte == 0) ? 0 : byte - (lastcore_count - (lastcore_count / byte) * byte);
    tiling_params->e_num_front_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_num_last_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_ub2gm_front_burst_len_input_scalar_lastcore = lastcore_count * comm_paras.ele_byte / BYTE_BLOCK;
    tiling_params->e_ub2gm_last_burst_len_input_scalar_lastcore =
        tiling_params->e_ub2gm_front_burst_len_input_scalar_lastcore;
    if (tiling_params->e_ub2gm_front_burst_len_input_scalar_lastcore < 1) {
        tiling_params->e_ub2gm_front_burst_len_input_scalar_lastcore = 1;
    }
    tiling_params->front_num_segment_lastcore = tiling_params->num_segments_last_core_input_scalar;
    tiling_params->front_num_segment_last_lastcore = tiling_params->num_segments_last_core_input_scalar;
    tiling_params->e_gm2ub_last_burst_len_input_scalar = 1;
    tiling_params->repeat_time_last_part_input_scalar = 1;
    tiling_params->e_gm2ub_front_burst_len_input_scalar = 1;
    tiling_params->repeat_time_front_part_input_scalar = 1;

    return;
}

static void ComputeENumParamsLastInputScalarGTSegmentMax(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;

    tiling_params->num_segment_max_time_lastcore =
        tiling_params->num_segments_last_core_input_scalar / tiling_params->num_segment_max;
    tiling_params->num_segment_max_time_lastcore =
        (tiling_params->num_segments_last_core_input_scalar % tiling_params->num_segment_max == 0) ?
        tiling_params->num_segment_max_time_lastcore :
        tiling_params->num_segment_max_time_lastcore + 1;
    tiling_params->front_num_segment_lastcore = tiling_params->num_segment_max;
    tiling_params->front_num_segment_last_lastcore = tiling_params->num_segments_last_core_input_scalar -
        tiling_params->num_segment_max * (tiling_params->num_segment_max_time_lastcore - 1);
    if (tiling_params->front_num_segment_last_lastcore * tiling_params->e_num_input_scalar < byte) {
        tiling_params->front_num_segment_last_lastcore = byte;
        int32_t front =
            tiling_params->num_segments_last_core_input_scalar - tiling_params->front_num_segment_last_lastcore;
        int32_t num_segment_max_lastcore_front =
            (front / (tiling_params->num_segment_max_time_lastcore - 1) / byte) * byte;
        tiling_params->front_num_segment_lastcore = num_segment_max_lastcore_front;
        tiling_params->front_num_segment_last_lastcore = tiling_params->num_segments_last_core_input_scalar -
            tiling_params->front_num_segment_lastcore * (tiling_params->num_segment_max_time_lastcore - 1);
    }

    tiling_params->align_scalar_lastcore =
        (tiling_params->front_num_segment_last_lastcore * tiling_params->e_num_input_scalar % byte == 0) ?
        0 :
        byte - (tiling_params->front_num_segment_last_lastcore * tiling_params->e_num_input_scalar -
        (tiling_params->front_num_segment_last_lastcore * tiling_params->e_num_input_scalar / byte) * byte);
    tiling_params->e_ub2gm_front_burst_len_input_scalar_lastcore = tiling_params->front_num_segment_lastcore *
        tiling_params->e_num_input_scalar * comm_paras.ele_byte / BYTE_BLOCK;
    tiling_params->e_gm2ub_front_burst_len_input_scalar = 1;
    tiling_params->repeat_time_front_part_input_scalar = 1;

    tiling_params->e_num_front_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_num_last_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_ub2gm_last_burst_len_input_scalar_lastcore = tiling_params->front_num_segment_last_lastcore *
        tiling_params->e_num_input_scalar * comm_paras.ele_byte / BYTE_BLOCK;
    tiling_params->e_gm2ub_last_burst_len_input_scalar = 1;
    tiling_params->repeat_time_last_part_input_scalar = 1;

    return;
}

static void ComputeENumParamsInputScalarLTOneBlockNum(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    if (tiling_params->num_segments_front_core_input_scalar <= tiling_params->num_segment_max) {
        ComputeENumParamsFrontInputScalarLESegmentMax(comm_paras, tiling_params);
    } else {
        ComputeENumParamsFrontInputScalarGTSegmentMax(comm_paras, tiling_params);
    }

    if (tiling_params->num_segments_last_core_input_scalar < tiling_params->num_segment_max) {
        ComputeENumParamsLastInputScalarLTSegmentMax(comm_paras, tiling_params);
    } else if (tiling_params->num_segments_last_core_input_scalar > tiling_params->num_segment_max) {
        ComputeENumParamsLastInputScalarGTSegmentMax(comm_paras, tiling_params);
    }
}
static void ComputeENumParamsLTMaxEleNum(const CommParas4Int32 &comm_paras,
    UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;

    tiling_params->e_mov_times_gm2ub_input_scalar = 1;
    if (tiling_params->e_num_input_scalar >= byte || tiling_params->need_core_num_input_scalar == 1) {
        ComputeENumParamsInputScalarGEOneBlockNum(comm_paras, tiling_params);
    } else {
        ComputeENumParamsInputScalarLTOneBlockNum(comm_paras, tiling_params);
    }

    return;
}

static void ComputeENumParams(const CommParas4Int32 &comm_paras, UnsortedSegmentSumTilingParamsInt32 *tiling_params)
{
    int32_t max_ele_num_one_ub_tensor = comm_paras.e_once_num;
    int32_t mask = (comm_paras.input_dytpe == ge::DT_INT32) ? MASK_INT32 : MASK_FP16;
    int32_t byte = (comm_paras.input_dytpe == ge::DT_INT32) ? INT32_BLOCK_NUM : FP16_BLOCK_NUM;
    if (tiling_params->e_num_input_scalar % byte == 0 && tiling_params->e_num_input_scalar > byte) {
        tiling_params->align_scalar = 0;
    } else if (tiling_params->e_num_input_scalar % byte != 0 && tiling_params->e_num_input_scalar > byte) {
        tiling_params->align_scalar =
            byte - (tiling_params->e_num_input_scalar - (tiling_params->e_num_input_scalar / byte) * byte);
    }

    if (tiling_params->e_num_input_scalar >= max_ele_num_one_ub_tensor && comm_paras.num_segments > 1) {
        ComputeENumParamsGEMaxEleNum(comm_paras, tiling_params);
    } else if (comm_paras.num_segments > 1 && tiling_params->e_num_input_scalar < max_ele_num_one_ub_tensor) {
        ComputeENumParamsLTMaxEleNum(comm_paras, tiling_params);
    } else if (comm_paras.num_segments == 1) {
        tiling_params->e_mov_times_gm2ub_input_scalar =
            UssCeilDiv(tiling_params->num_segments_front_core_input_scalar, max_ele_num_one_ub_tensor);
        tiling_params->e_mov_times_gm2ub_input_scalar_lastcore =
            UssCeilDiv(tiling_params->num_segments_last_core_input_scalar, max_ele_num_one_ub_tensor);
        // front core
        uint32_t mode = FRONT_CORE;
        NumSegmentOne(max_ele_num_one_ub_tensor, mask, comm_paras.ele_byte, mode, tiling_params);
        // last core
        mode = LAST_CORE;
        NumSegmentOne(max_ele_num_one_ub_tensor, mask, comm_paras.ele_byte, mode, tiling_params);
    }

    return;
}

static void InitTilingParams(UnsortedSegmentSumTilingParamsFp32 *tiling_params, const int32_t num_segments)
{
    // common params
    tiling_params->select_key_input_scalar = 0;
    tiling_params->need_core_num_input_scalar = 0;

    // input data params
    // front core
    tiling_params->input_ele_num_front_core_input_scalar = 0;
    // front part front core
    tiling_params->input_mov_times_gm2ub_front_part_front_core_input_scalar = 0;
    tiling_params->input_front_burst_len_front_part_front_core_input_scalar = 0;
    tiling_params->input_last_burst_len_front_part_front_core_input_scalar = 0;
    tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar = 0;
    tiling_params->input_last_ele_num_ub_front_part_front_core_input_scalar = 0;
    tiling_params->input_front_rows_front_part_front_core_input_scalar = 0;
    tiling_params->input_last_rows_front_part_front_core_input_scalar = 0;
    // last part front core
    tiling_params->input_mov_times_gm2ub_last_part_front_core_input_scalar = 0;
    tiling_params->input_front_burst_len_last_part_front_core_input_scalar = 0;
    tiling_params->input_last_burst_len_last_part_front_core_input_scalar = 0;
    tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar = 0;
    tiling_params->input_last_ele_num_ub_last_part_front_core_input_scalar = 0;
    tiling_params->input_front_rows_last_part_front_core_input_scalar = 0;
    tiling_params->input_last_rows_last_part_front_core_input_scalar = 0;
    // last core
    tiling_params->input_ele_num_last_core_input_scalar = 0;
    // front part last core
    tiling_params->input_mov_times_gm2ub_front_part_last_core_input_scalar = 0;
    tiling_params->input_front_burst_len_front_part_last_core_input_scalar = 0;
    tiling_params->input_last_burst_len_front_part_last_core_input_scalar = 0;
    tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar = 0;
    tiling_params->input_last_ele_num_ub_front_part_last_core_input_scalar = 0;
    tiling_params->input_front_rows_front_part_last_core_input_scalar = 0;
    tiling_params->input_last_rows_front_part_last_core_input_scalar = 0;
    // last part last core
    tiling_params->input_mov_times_gm2ub_last_part_last_core_input_scalar = 0;
    tiling_params->input_front_burst_len_last_part_last_core_input_scalar = 0;
    tiling_params->input_last_burst_len_last_part_last_core_input_scalar = 0;
    tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar = 0;
    tiling_params->input_last_ele_num_ub_last_part_last_core_input_scalar = 0;
    tiling_params->input_front_rows_last_part_last_core_input_scalar = 0;
    tiling_params->input_last_rows_last_part_last_core_input_scalar = 0;

    // e num params
    tiling_params->e_num_input_scalar = 0;
    tiling_params->e_mov_times_gm2ub_input_scalar = 0;
    tiling_params->e_ub2gm_front_burst_len_input_scalar = 0;
    tiling_params->e_num_front_part_input_scalar = 0;
    tiling_params->e_ub2gm_last_burst_len_input_scalar = 0;
    tiling_params->e_gm2ub_last_burst_len_input_scalar = 0;
    tiling_params->e_num_last_part_input_scalar = 0;

    // ids params
    tiling_params->ids_size_input_scalar = 0;
    tiling_params->ids_ele_num_front_core_input_scalar = 0;
    tiling_params->ids_mov_times_gm2ub_front_core_input_scalar = 0;
    tiling_params->ids_front_burst_len_front_core_input_scalar = 0;
    tiling_params->ids_last_burst_len_front_core_input_scalar = 0;
    tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar = 0;
    tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar = 0;
    tiling_params->ids_ele_num_last_core_input_scalar = 0;
    tiling_params->ids_mov_times_gm2ub_last_core_input_scalar = 0;
    tiling_params->ids_front_burst_len_last_core_input_scalar = 0;
    tiling_params->ids_last_burst_len_last_core_input_scalar = 0;
    tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar = 0;
    tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar = 0;

    // output init params
    tiling_params->output_ub_init_last_repeat_time_front_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_times_front_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_last_repeat_time_last_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_times_last_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_last_repeat_time_front_part_last_core_input_scalar = 0;
    tiling_params->output_ub_init_times_front_part_last_core_input_scalar = 0;
    tiling_params->output_ub_init_last_repeat_time_last_part_last_core_input_scalar = 0;
    tiling_params->output_ub_init_times_last_part_last_core_input_scalar = 0;
    tiling_params->input_last_axis_align_front_part_ele_num_input_scalar = 0;
    tiling_params->input_last_axis_align_floor_ele_num_input_scalar = 0;
    tiling_params->last_part_vadd_mask_input_scalar = 0;
    tiling_params->output_ub_init_last_row_last_repeat_time_front_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_last_row_times_front_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_last_row_last_repeat_time_last_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_last_row_times_last_part_front_core_input_scalar = 0;
    tiling_params->output_ub_init_last_row_last_repeat_time_front_part_last_core_input_scalar = 0;
    tiling_params->output_ub_init_last_row_times_front_part_last_core_input_scalar = 0;
    tiling_params->output_ub_init_last_row_last_repeat_time_last_part_last_core_input_scalar = 0;
    tiling_params->output_ub_init_last_row_times_last_part_last_core_input_scalar = 0;

    // num_segments init params
    tiling_params->num_segments = num_segments;

    tiling_params->tiling_core_num = 0;

    tiling_params->repeat_front_front_part_front_core = 0;
    tiling_params->col_sub_block_front_front_part_front_core = 0;
    tiling_params->repeat_last_front_part_front_core = 0;
    tiling_params->col_sub_block_last_front_part_front_core = 0;
    tiling_params->repeat_front_last_part_front_core = 0;
    tiling_params->col_sub_block_front_last_part_front_core = 0;
    tiling_params->repeat_last_last_part_front_core = 0;
    tiling_params->col_sub_block_last_last_part_front_core = 0;
    tiling_params->repeat_front_front_part_last_core = 0;
    tiling_params->col_sub_block_front_front_part_last_core = 0;
    tiling_params->repeat_last_front_part_last_core = 0;
    tiling_params->col_sub_block_last_front_part_last_core = 0;
    tiling_params->repeat_front_last_part_last_core = 0;
    tiling_params->col_sub_block_front_last_part_last_core = 0;
    tiling_params->repeat_last_last_part_last_core = 0;
    tiling_params->col_sub_block_last_last_part_last_core = 0;
    tiling_params->e_num_sub = 0;
    tiling_params->vadd_repeat_255 = 0;
    tiling_params->vadd_repeat_64 = 0;
    tiling_params->vadd_repeat_last = 0;
    tiling_params->max_cache_n_num = 0;
    tiling_params->repeat_remove_pad = 0;
    tiling_params->col_block_remove_pad = 0;
    tiling_params->cache_num_block = 0;

    return;
}

static void InitTilingParams(UnsortedSegmentSumTilingParamsInt32 *tiling_params, const int32_t num_segments)
{
    // common params
    tiling_params->select_key_input_scalar = 0;
    tiling_params->need_core_num_input_scalar = 0;
    tiling_params->num_segments_front_core_input_scalar = 0;
    tiling_params->num_segments_last_core_input_scalar = 0;

    // ids params
    tiling_params->ids_size_input_scalar = 0;
    tiling_params->ids_mov_times_gm2ub_input_scalar = 0;
    tiling_params->ids_ele_num_ub_front_part_input_scalar = 0;
    tiling_params->ids_front_burst_len_input_scalar = 0;
    tiling_params->ids_ele_num_ub_last_part_input_scalar = 0;
    tiling_params->ids_last_burst_len_input_scalar = 0;

    // e num params
    tiling_params->e_num_input_scalar = 0;
    tiling_params->e_mov_times_gm2ub_input_scalar = 0;
    tiling_params->e_ub2gm_front_burst_len_input_scalar = 0;
    tiling_params->e_num_front_part_input_scalar = 0;
    tiling_params->repeat_time_front_part_input_scalar = 0;
    tiling_params->e_ub2gm_last_burst_len_input_scalar = 0;
    tiling_params->e_num_last_part_input_scalar = 0;
    tiling_params->repeat_time_last_part_input_scalar = 0;
    tiling_params->align_scalar = 0;
    tiling_params->align_scalar_lastcore = 0;
    tiling_params->e_gm2ub_front_burst_len_input_scalar = 0;
    tiling_params->e_gm2ub_last_burst_len_input_scalar = 0;
    tiling_params->num_segment_max = 0;
    tiling_params->num_segment_max_time = 0;
    tiling_params->num_segment_max_time_lastcore = 0;
    tiling_params->front_num_segment = 0;
    tiling_params->front_num_segment_last = 0;
    tiling_params->front_num_segment_lastcore = 0;
    tiling_params->front_num_segment_last_lastcore = 0;
    tiling_params->e_ub2gm_front_burst_len_input_scalar_lastcore = 0;
    tiling_params->e_ub2gm_last_burst_len_input_scalar_lastcore = 0;
    tiling_params->repeat_times = 0;
    tiling_params->repeat_times_last_part = 0;
    tiling_params->repeat_times_last_part_lastcore = 0;
    tiling_params->e_mov_times_gm2ub_input_scalar_lastcore = 0;
    tiling_params->repeat_time_front_part_input_scalar_lastcore = 0;

    // num_segments init params
    tiling_params->num_segments = num_segments;

    tiling_params->tiling_core_num = 0;

    return;
}

static void PrintTilingParamsPartOne(gert::TilingContext *context,
    const UnsortedSegmentSumTilingParamsFp32 *tiling_param)
{
    HCCL_DEBUG("tiling_param->select_key_input_scalar=%d", tiling_param->select_key_input_scalar);
    HCCL_DEBUG("tiling_param->need_core_num_input_scalar=%d", tiling_param->need_core_num_input_scalar);
    HCCL_DEBUG("tiling_param->input_ele_num_front_core_input_scalar=%d",
        tiling_param->input_ele_num_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_mov_times_gm2ub_front_part_front_core_input_scalar=%d",
        tiling_param->input_mov_times_gm2ub_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_burst_len_front_part_front_core_input_scalar=%d",
        tiling_param->input_front_burst_len_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_burst_len_front_part_front_core_input_scalar=%d",
        tiling_param->input_last_burst_len_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_ele_num_ub_front_part_front_core_input_scalar=%d",
        tiling_param->input_front_ele_num_ub_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_ele_num_ub_front_part_front_core_input_scalar=%d",
        tiling_param->input_last_ele_num_ub_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_rows_front_part_front_core_input_scalar=%d",
        tiling_param->input_front_rows_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_rows_front_part_front_core_input_scalar=%d",
        tiling_param->input_last_rows_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_mov_times_gm2ub_last_part_front_core_input_scalar=%d",
        tiling_param->input_mov_times_gm2ub_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_burst_len_last_part_front_core_input_scalar=%d",
        tiling_param->input_front_burst_len_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_burst_len_last_part_front_core_input_scalar=%d",
        tiling_param->input_last_burst_len_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_ele_num_ub_last_part_front_core_input_scalar=%d",
        tiling_param->input_front_ele_num_ub_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_ele_num_ub_last_part_front_core_input_scalar=%d",
        tiling_param->input_last_ele_num_ub_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_rows_last_part_front_core_input_scalar=%d",
        tiling_param->input_front_rows_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_rows_last_part_front_core_input_scalar=%d",
        tiling_param->input_last_rows_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_ele_num_last_core_input_scalar=%d",
        tiling_param->input_ele_num_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_mov_times_gm2ub_front_part_last_core_input_scalar=%d",
        tiling_param->input_mov_times_gm2ub_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_burst_len_front_part_last_core_input_scalar=%d",
        tiling_param->input_front_burst_len_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_burst_len_front_part_last_core_input_scalar=%d",
        tiling_param->input_last_burst_len_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_ele_num_ub_front_part_last_core_input_scalar=%d",
        tiling_param->input_front_ele_num_ub_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_ele_num_ub_front_part_last_core_input_scalar=%d",
        tiling_param->input_last_ele_num_ub_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_rows_front_part_last_core_input_scalar=%d",
        tiling_param->input_front_rows_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_rows_front_part_last_core_input_scalar=%d",
        tiling_param->input_last_rows_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_mov_times_gm2ub_last_part_last_core_input_scalar=%d",
        tiling_param->input_mov_times_gm2ub_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_burst_len_last_part_last_core_input_scalar=%d",
        tiling_param->input_front_burst_len_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_burst_len_last_part_last_core_input_scalar=%d",
        tiling_param->input_last_burst_len_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_ele_num_ub_last_part_last_core_input_scalar=%d",
        tiling_param->input_front_ele_num_ub_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_ele_num_ub_last_part_last_core_input_scalar=%d",
        tiling_param->input_last_ele_num_ub_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_front_rows_last_part_last_core_input_scalar=%d",
        tiling_param->input_front_rows_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_rows_last_part_last_core_input_scalar=%d",
        tiling_param->input_last_rows_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->e_num_input_scalar=%d", tiling_param->e_num_input_scalar);
    HCCL_DEBUG("tiling_param->e_mov_times_gm2ub_input_scalar=%d", tiling_param->e_mov_times_gm2ub_input_scalar);
    HCCL_DEBUG("tiling_param->e_ub2gm_front_burst_len_input_scalar=%d",
        tiling_param->e_ub2gm_front_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->e_num_front_part_input_scalar=%d", tiling_param->e_num_front_part_input_scalar);
    HCCL_DEBUG("tiling_param->e_ub2gm_last_burst_len_input_scalar=%d",
        tiling_param->e_ub2gm_last_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->e_num_last_part_input_scalar=%d", tiling_param->e_num_last_part_input_scalar);
    return;
}

static void PrintTilingParamsPartTwo(gert::TilingContext *context,
    const UnsortedSegmentSumTilingParamsFp32 *tiling_param)
{
    HCCL_DEBUG("tiling_param->ids_size_input_scalar=%d", tiling_param->ids_size_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_front_core_input_scalar=%d",
        tiling_param->ids_ele_num_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_mov_times_gm2ub_front_core_input_scalar=%d",
        tiling_param->ids_mov_times_gm2ub_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_front_burst_len_front_core_input_scalar=%d",
        tiling_param->ids_front_burst_len_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_last_burst_len_front_core_input_scalar=%d",
        tiling_param->ids_last_burst_len_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_ub_front_part_front_core_input_scalar=%d",
        tiling_param->ids_ele_num_ub_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_ub_last_part_front_core_input_scalar=%d",
        tiling_param->ids_ele_num_ub_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_last_core_input_scalar=%d", tiling_param->ids_ele_num_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_mov_times_gm2ub_last_core_input_scalar=%d",
        tiling_param->ids_mov_times_gm2ub_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_front_burst_len_last_core_input_scalar=%d",
        tiling_param->ids_front_burst_len_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_last_burst_len_last_core_input_scalar=%d",
        tiling_param->ids_last_burst_len_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_ub_front_part_last_core_input_scalar=%d",
        tiling_param->ids_ele_num_ub_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_ub_last_part_last_core_input_scalar=%d",
        tiling_param->ids_ele_num_ub_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_repeat_time_front_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_last_repeat_time_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_times_front_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_times_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_repeat_time_last_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_last_repeat_time_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_times_last_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_times_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_repeat_time_front_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_last_repeat_time_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_times_front_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_times_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_repeat_time_last_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_last_repeat_time_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_times_last_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_times_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_axis_align_front_part_ele_num_input_scalar=%d",
        tiling_param->input_last_axis_align_front_part_ele_num_input_scalar);
    HCCL_DEBUG("tiling_param->input_last_axis_align_floor_ele_num_input_scalar=%d",
        tiling_param->input_last_axis_align_floor_ele_num_input_scalar);
    HCCL_DEBUG("tiling_param->last_part_vadd_mask_input_scalar=%d", tiling_param->last_part_vadd_mask_input_scalar);
    HCCL_DEBUG("tiling_param->e_gm2ub_last_burst_len_input_scalar=%d",
        tiling_param->e_gm2ub_last_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_last_repeat_time_front_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_last_repeat_time_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_times_front_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_times_front_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_last_repeat_time_last_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_last_repeat_time_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_times_last_part_front_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_times_last_part_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_last_repeat_time_front_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_last_repeat_time_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_times_front_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_times_front_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_last_repeat_time_last_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_last_repeat_time_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->output_ub_init_last_row_times_last_part_last_core_input_scalar=%d",
        tiling_param->output_ub_init_last_row_times_last_part_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->num_segments=%d", tiling_param->num_segments);

    HCCL_DEBUG("tiling_param->tiling_core_num=%d", tiling_param->tiling_core_num);

    return;
}

static void PrintTilingParamsPartThree(gert::TilingContext *context,
    const UnsortedSegmentSumTilingParamsFp32 *tiling_param)
{
    HCCL_DEBUG("tiling_param->repeat_front_front_part_front_core=%d", tiling_param->repeat_front_front_part_front_core);
    HCCL_DEBUG("tiling_param->col_sub_block_front_front_part_front_core=%d",
        tiling_param->col_sub_block_front_front_part_front_core);
    HCCL_DEBUG("tiling_param->repeat_last_front_part_front_core=%d", tiling_param->repeat_last_front_part_front_core);
    HCCL_DEBUG("tiling_param->col_sub_block_last_front_part_front_core=%d",
        tiling_param->col_sub_block_last_front_part_front_core);
    HCCL_DEBUG("tiling_param->repeat_front_last_part_front_core=%d", tiling_param->repeat_front_last_part_front_core);
    HCCL_DEBUG("tiling_param->col_sub_block_front_last_part_front_core=%d",
        tiling_param->col_sub_block_front_last_part_front_core);
    HCCL_DEBUG("tiling_param->repeat_last_last_part_front_core=%d", tiling_param->repeat_last_last_part_front_core);
    HCCL_DEBUG("tiling_param->col_sub_block_last_last_part_front_core=%d",
        tiling_param->col_sub_block_last_last_part_front_core);
    HCCL_DEBUG("tiling_param->repeat_front_front_part_last_core=%d", tiling_param->repeat_front_front_part_last_core);
    HCCL_DEBUG("tiling_param->col_sub_block_front_front_part_last_core=%d",
        tiling_param->col_sub_block_front_front_part_last_core);
    HCCL_DEBUG("tiling_param->repeat_last_front_part_last_core=%d", tiling_param->repeat_last_front_part_last_core);
    HCCL_DEBUG("tiling_param->col_sub_block_last_front_part_last_core=%d",
        tiling_param->col_sub_block_last_front_part_last_core);
    HCCL_DEBUG("tiling_param->repeat_front_last_part_last_core=%d", tiling_param->repeat_front_last_part_last_core);
    HCCL_DEBUG("tiling_param->col_sub_block_front_last_part_last_core=%d",
        tiling_param->col_sub_block_front_last_part_last_core);
    HCCL_DEBUG("tiling_param->repeat_last_last_part_last_core=%d", tiling_param->repeat_last_last_part_last_core);
    HCCL_DEBUG("tiling_param->col_sub_block_last_last_part_last_core=%d",
        tiling_param->col_sub_block_last_last_part_last_core);
    HCCL_DEBUG("tiling_param->e_num_sub=%d", tiling_param->e_num_sub);
    HCCL_DEBUG("tiling_param->vadd_repeat_255=%d", tiling_param->vadd_repeat_255);
    HCCL_DEBUG("tiling_param->vadd_repeat_64=%d", tiling_param->vadd_repeat_64);
    HCCL_DEBUG("tiling_param->vadd_repeat_last=%d", tiling_param->vadd_repeat_last);
    HCCL_DEBUG("tiling_param->move_pad=%d", tiling_param->move_pad);
    HCCL_DEBUG("tiling_param->max_cache_n_num=%d", tiling_param->max_cache_n_num);
    HCCL_DEBUG("tiling_param->repeat_remove_pad=%d", tiling_param->repeat_remove_pad);
    HCCL_DEBUG("tiling_param->col_block_remove_pad=%d", tiling_param->col_block_remove_pad);
    HCCL_DEBUG("tiling_param->cache_num_block=%d", tiling_param->cache_num_block);
    return;
}

static void PrintTilingParams(gert::TilingContext *context, const UnsortedSegmentSumTilingParamsFp32 *tiling_param)
{
    PrintTilingParamsPartOne(context, tiling_param);
    PrintTilingParamsPartTwo(context, tiling_param);
    PrintTilingParamsPartThree(context, tiling_param);
    return;
}

static void PrintTilingParams(gert::TilingContext *context, const UnsortedSegmentSumTilingParamsInt32 *tiling_param)
{
    HCCL_DEBUG("tiling_param->select_key_input_scalar=%d", tiling_param->select_key_input_scalar);
    HCCL_DEBUG("tiling_param->need_core_num_input_scalar=%d", tiling_param->need_core_num_input_scalar);
    HCCL_DEBUG("tiling_param->num_segments_front_core_input_scalar=%d",
        tiling_param->num_segments_front_core_input_scalar);
    HCCL_DEBUG("tiling_param->num_segments_last_core_input_scalar=%d",
        tiling_param->num_segments_last_core_input_scalar);
    HCCL_DEBUG("tiling_param->ids_size_input_scalar=%d", tiling_param->ids_size_input_scalar);
    HCCL_DEBUG("tiling_param->ids_mov_times_gm2ub_input_scalar=%d", tiling_param->ids_mov_times_gm2ub_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_ub_front_part_input_scalar=%d",
        tiling_param->ids_ele_num_ub_front_part_input_scalar);
    HCCL_DEBUG("tiling_param->ids_front_burst_len_input_scalar=%d", tiling_param->ids_front_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->ids_ele_num_ub_last_part_input_scalar=%d",
        tiling_param->ids_ele_num_ub_last_part_input_scalar);
    HCCL_DEBUG("tiling_param->ids_last_burst_len_input_scalar=%d", tiling_param->ids_last_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->e_num_input_scalar=%d", tiling_param->e_num_input_scalar);
    HCCL_DEBUG("tiling_param->e_mov_times_gm2ub_input_scalar=%d", tiling_param->e_mov_times_gm2ub_input_scalar);
    HCCL_DEBUG("tiling_param->e_ub2gm_front_burst_len_input_scalar=%d",
        tiling_param->e_ub2gm_front_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->e_num_front_part_input_scalar=%d", tiling_param->e_num_front_part_input_scalar);
    HCCL_DEBUG("tiling_param->repeat_time_front_part_input_scalar=%d",
        tiling_param->repeat_time_front_part_input_scalar);
    HCCL_DEBUG("tiling_param->e_ub2gm_last_burst_len_input_scalar=%d",
        tiling_param->e_ub2gm_last_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->e_num_last_part_input_scalar=%d", tiling_param->e_num_last_part_input_scalar);
    HCCL_DEBUG("tiling_param->repeat_time_last_part_input_scalar=%d", tiling_param->repeat_time_last_part_input_scalar);

    HCCL_DEBUG("tiling_param->align_scalar=%d", tiling_param->align_scalar);
    HCCL_DEBUG("tiling_param->align_scalar_lastcore=%d", tiling_param->align_scalar_lastcore);
    HCCL_DEBUG("tiling_param->e_gm2ub_front_burst_len_input_scalar=%d",
        tiling_param->e_gm2ub_front_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->e_gm2ub_last_burst_len_input_scalar=%d",
        tiling_param->e_gm2ub_last_burst_len_input_scalar);
    HCCL_DEBUG("tiling_param->num_segment_max=%d", tiling_param->num_segment_max);
    HCCL_DEBUG("tiling_param->num_segment_max_time=%d", tiling_param->num_segment_max_time);
    HCCL_DEBUG("tiling_param->num_segment_max_time_lastcore=%d", tiling_param->num_segment_max_time_lastcore);
    HCCL_DEBUG("tiling_param->front_num_segment=%d", tiling_param->front_num_segment);
    HCCL_DEBUG("tiling_param->front_num_segment_last=%d", tiling_param->front_num_segment_last);
    HCCL_DEBUG("tiling_param->front_num_segment_lastcore=%d", tiling_param->front_num_segment_lastcore);
    HCCL_DEBUG("tiling_param->front_num_segment_last_lastcore=%d", tiling_param->front_num_segment_last_lastcore);
    HCCL_DEBUG("tiling_param->e_ub2gm_front_burst_len_input_scalar_lastcore=%d",
        tiling_param->e_ub2gm_front_burst_len_input_scalar_lastcore);
    HCCL_DEBUG("tiling_param->e_ub2gm_last_burst_len_input_scalar_lastcore=%d",
        tiling_param->e_ub2gm_last_burst_len_input_scalar_lastcore);
    HCCL_DEBUG("tiling_param->repeat_times=%d", tiling_param->repeat_times);
    HCCL_DEBUG("tiling_param->repeat_times_last_part=%d", tiling_param->repeat_times_last_part);
    HCCL_DEBUG("tiling_param->repeat_times_last_part_lastcore=%d", tiling_param->repeat_times_last_part_lastcore);
    HCCL_DEBUG("tiling_param->e_mov_times_gm2ub_input_scalar_lastcore=%d",
        tiling_param->e_mov_times_gm2ub_input_scalar_lastcore);
    HCCL_DEBUG("tiling_param->repeat_time_front_part_input_scalar_lastcore=%d",
        tiling_param->repeat_time_front_part_input_scalar_lastcore);
    HCCL_DEBUG("tiling_param->num_segments=%d", tiling_param->num_segments);

    HCCL_DEBUG("tiling_param->tiling_core_num=%d", tiling_param->tiling_core_num);

    return;
}

ge::graphStatus CalcSpecialTiling(gert::TilingContext *context, const uint32_t num_segments)
{
    auto tiling_params = context->GetTilingData<UnsortedSegmentSumTilingParamsFp32>();
    if (tiling_params == nullptr) {
        HCCL_ERROR("tiling_params is null");
        return ge::GRAPH_FAILED;
    }

    auto compile_info =
        reinterpret_cast<const TilingPrepareForUnsortedSegmentSumCompileInfo *>(context->GetCompileInfo());
    if (compile_info == nullptr) {
        HCCL_ERROR("compile_info is null");
        return ge::GRAPH_FAILED;
    }

    InitTilingParams(tiling_params, num_segments);
    tiling_params->select_key_input_scalar = 0;
    tiling_params->need_core_num_input_scalar = 1;
    tiling_params->tiling_core_num = compile_info->core_num;
    // cout tiling params
    PrintTilingParams(context, tiling_params);
    // BlockDim, core num used in tik op
    context->SetBlockDim(tiling_params->need_core_num_input_scalar);

    return ge::GRAPH_SUCCESS;
}

void CalcTilingFloat4LastAxisSmallE(UnsortedSegmentSumTilingParamsFp32 *tiling_params, const CommParas &comm_paras,
    const int32_t x_ub_size, const EleByte input_ele_byte, const int32_t e_size)
{
    // aign small e
    // e num params
    tiling_params->e_mov_times_gm2ub_input_scalar = 1;
    tiling_params->e_num_front_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_num_last_part_input_scalar = tiling_params->e_num_input_scalar;
    tiling_params->e_ub2gm_front_burst_len_input_scalar =
        tiling_params->e_num_front_part_input_scalar * input_ele_byte / BYTE_BLOCK;
    tiling_params->e_ub2gm_last_burst_len_input_scalar = tiling_params->e_ub2gm_front_burst_len_input_scalar;
    // input data params
    InputParamsGm2UbOut gm_ub_out_params = { 0 };

    // front part front core
    gm_ub_out_params.mode = FRONT_PART_FRONT_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);

    // last part front core
    gm_ub_out_params.mode = LAST_PART_FRONT_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);

    // front part last core
    gm_ub_out_params.mode = FRONT_PART_LAST_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);

    // last part last core
    gm_ub_out_params.mode = LAST_PART_LAST_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);
    bool perf = CheckHighPerf(comm_paras.ub_size, comm_paras.e_num, comm_paras.impl_mode);
    if (perf) {
        int32_t num = comm_paras.ub_tensor_ele_num / comm_paras.e_num;
        tiling_params->output_ub_init_last_repeat_time_front_part_front_core_input_scalar = num;
        if (num > comm_paras.num_segments) {
            tiling_params->output_ub_init_last_repeat_time_front_part_front_core_input_scalar = comm_paras.num_segments;
        }
        ComputeDiv(comm_paras.e_num, MASK_FP32 * MAX_REPEAT_TIME,
            tiling_params->output_ub_init_times_front_part_front_core_input_scalar,
            tiling_params->output_ub_init_last_repeat_time_last_part_front_core_input_scalar);
        ComputeDiv(tiling_params->output_ub_init_last_repeat_time_last_part_front_core_input_scalar, MASK_FP32,
            tiling_params->last_part_vadd_mask_input_scalar,
            tiling_params->output_ub_init_last_repeat_time_front_part_last_core_input_scalar);
        if (num <= comm_paras.num_segments) {
            tiling_params->output_ub_init_times_front_part_last_core_input_scalar =
                (comm_paras.e_num * num * MULTI) / BYTE_BLOCK;
        } else {
            tiling_params->output_ub_init_times_front_part_last_core_input_scalar =
                (comm_paras.e_num * comm_paras.num_segments * MULTI) / BYTE_BLOCK;
        }
    }
    return;
}

void CalcTilingFloat4LastAxisOne(UnsortedSegmentSumTilingParamsFp32 *tiling_params,
    const int32_t output_ub_ele_num_one_row)
{
    // last axis is one

    // e num params
    tiling_params->e_num_input_scalar = 1;
    tiling_params->e_mov_times_gm2ub_input_scalar = 1;
    tiling_params->e_ub2gm_front_burst_len_input_scalar = 1;

    // input data params
    // front part front core
    tiling_params->input_front_burst_len_front_part_front_core_input_scalar =
        tiling_params->ids_front_burst_len_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar;
    tiling_params->input_front_rows_front_part_front_core_input_scalar =
        tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar;
    // last part front core
    tiling_params->input_front_burst_len_last_part_front_core_input_scalar =
        tiling_params->ids_last_burst_len_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar;
    tiling_params->input_front_rows_last_part_front_core_input_scalar =
        tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar;
    // front part last core
    tiling_params->input_front_burst_len_front_part_last_core_input_scalar =
        tiling_params->ids_front_burst_len_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar;
    tiling_params->input_front_rows_front_part_last_core_input_scalar =
        tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar;
    // last part last core
    tiling_params->input_front_burst_len_last_part_last_core_input_scalar =
        tiling_params->ids_last_burst_len_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar;
    tiling_params->input_front_rows_last_part_last_core_input_scalar =
        tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar;

    // output init params
    // front part front core
    ComputeInitOutputUbParams(tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, 0);
    // last part front core
    ComputeInitOutputUbParams(tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_TWO);
    // front part last core
    ComputeInitOutputUbParams(tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_FOUR);
    // last part last core
    ComputeInitOutputUbParams(tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar, output_ub_ele_num_one_row,
        tiling_params, PART_SIX);

    return;
}

void CalcTilingFloat4LastAxisNotAlignSmallE(UnsortedSegmentSumTilingParamsFp32 *tiling_params, const int32_t x_ub_size,
    const EleByte input_ele_byte, const CommParas &comm_paras, const int32_t output_ub_ele_num_one_row)
{
    // not align small e
    // e num params
    int32_t e_size = comm_paras.e_num;
    tiling_params->e_mov_times_gm2ub_input_scalar = 1;
    tiling_params->e_ub2gm_front_burst_len_input_scalar = e_size * input_ele_byte / BYTE_BLOCK;

    tiling_params->e_num_front_part_input_scalar = e_size / FP32_ELE_NUM_ALIGN_32B * FP32_ELE_NUM_ALIGN_32B;
    tiling_params->e_ub2gm_last_burst_len_input_scalar = 1;
    tiling_params->e_num_last_part_input_scalar = e_size - tiling_params->e_num_front_part_input_scalar;

    // input data params
    InputParamsGm2UbOut gm_ub_out_params = { 0 };

    // front part front core
    gm_ub_out_params.mode = FRONT_PART_FRONT_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);

    // last part front core
    gm_ub_out_params.mode = LAST_PART_FRONT_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);

    // front part last core
    gm_ub_out_params.mode = FRONT_PART_LAST_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);

    // last part last core
    gm_ub_out_params.mode = LAST_PART_LAST_CORE;
    ComputeInputParamsMovGm2ub(x_ub_size, input_ele_byte, e_size, tiling_params, gm_ub_out_params);
    SetInputParamsMovGm2ub(gm_ub_out_params, tiling_params);

    // output init params
    // front row front part front core
    ComputeInitOutputUbParams(tiling_params->input_front_rows_front_part_front_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, 0);
    // last row front part front core
    ComputeInitOutputUbParams(tiling_params->input_last_rows_front_part_front_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, 1);
    // front row last part front core
    ComputeInitOutputUbParams(tiling_params->input_front_rows_last_part_front_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_TWO);
    // last row last part front core
    ComputeInitOutputUbParams(tiling_params->input_last_rows_last_part_front_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_THREE);
    // front row front part last core
    ComputeInitOutputUbParams(tiling_params->input_front_rows_front_part_last_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_FOUR);
    // last row front part last core
    ComputeInitOutputUbParams(tiling_params->input_last_rows_front_part_last_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_FIVE);
    // front row last part last core
    ComputeInitOutputUbParams(tiling_params->input_front_rows_last_part_last_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_SIX);
    // last row last part last core
    ComputeInitOutputUbParams(tiling_params->input_last_rows_last_part_last_core_input_scalar,
        output_ub_ele_num_one_row, tiling_params, PART_SERVERN);
    tiling_params->input_last_axis_align_front_part_ele_num_input_scalar =
        e_size / FP32_ELE_NUM_ALIGN_32B * FP32_ELE_NUM_ALIGN_32B;

    tiling_params->last_part_vadd_mask_input_scalar =
        e_size - tiling_params->input_last_axis_align_front_part_ele_num_input_scalar;
    ComputeDiv(comm_paras.e_num, MASK_FP32 * MAX_REPEAT_TIME, tiling_params->vadd_repeat_255,
        tiling_params->vadd_repeat_last);
    ComputeDiv(tiling_params->vadd_repeat_last, MASK_FP32, tiling_params->vadd_repeat_64,
        tiling_params->vadd_repeat_last);
}

void CalcTilingFloat4LastAxisAlignBigE(const int32_t x_ub_size, const EleByte input_ele_byte, const int32_t e_size,
    const int32_t ub_tensor_ele_num, UnsortedSegmentSumTilingParamsFp32 *tiling_params)
{
    // align big e
    // e num params
    tiling_params->e_mov_times_gm2ub_input_scalar = UssCeilDiv(e_size, ub_tensor_ele_num);
    tiling_params->e_ub2gm_front_burst_len_input_scalar = x_ub_size / BYTE_BLOCK;
    tiling_params->e_num_front_part_input_scalar = ub_tensor_ele_num;
    tiling_params->e_num_last_part_input_scalar = ComputeDivRemainders(e_size,
        tiling_params->e_num_front_part_input_scalar, tiling_params->e_mov_times_gm2ub_input_scalar - 1);
    tiling_params->e_ub2gm_last_burst_len_input_scalar =
        tiling_params->e_num_last_part_input_scalar * input_ele_byte / BYTE_BLOCK;

    // input data params
    // front part front core
    tiling_params->input_mov_times_gm2ub_front_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_front_part_front_core_input_scalar =
        tiling_params->e_num_last_part_input_scalar;
    // last part front core
    tiling_params->input_mov_times_gm2ub_last_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_last_part_front_core_input_scalar =
        tiling_params->e_num_last_part_input_scalar;
    // front part last core
    tiling_params->input_mov_times_gm2ub_front_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_front_part_last_core_input_scalar =
        tiling_params->e_num_last_part_input_scalar;
    // last part last core
    tiling_params->input_mov_times_gm2ub_last_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_last_part_last_core_input_scalar = tiling_params->e_num_last_part_input_scalar;

    return;
}

void CalcTilingFloat4LastAxisNotAlignBigE(UnsortedSegmentSumTilingParamsFp32 *tiling_params, const int32_t x_ub_size,
    const EleByte input_ele_byte, const int32_t e_size, const int32_t ub_tensor_ele_num)
{
    // not align big e
    // e num params
    tiling_params->e_mov_times_gm2ub_input_scalar = UssCeilDiv(e_size, ub_tensor_ele_num);
    tiling_params->e_ub2gm_front_burst_len_input_scalar = x_ub_size / BYTE_BLOCK;
    tiling_params->e_num_front_part_input_scalar = ub_tensor_ele_num;
    tiling_params->e_num_last_part_input_scalar = ComputeDivRemainders(e_size,
        tiling_params->e_num_front_part_input_scalar, tiling_params->e_mov_times_gm2ub_input_scalar - 1);
    tiling_params->e_ub2gm_last_burst_len_input_scalar =
        tiling_params->e_num_last_part_input_scalar * input_ele_byte / BYTE_BLOCK;
    tiling_params->e_gm2ub_last_burst_len_input_scalar =
        UssCeilDiv(tiling_params->e_num_last_part_input_scalar * input_ele_byte, BYTE_BLOCK);

    // input data params
    // front part front core
    tiling_params->input_mov_times_gm2ub_front_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_front_part_front_core_input_scalar =
        tiling_params->e_num_last_part_input_scalar;
    // last part front core
    tiling_params->input_mov_times_gm2ub_last_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_last_part_front_core_input_scalar =
        tiling_params->e_num_last_part_input_scalar;
    // front part last core
    tiling_params->input_mov_times_gm2ub_front_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_front_part_last_core_input_scalar =
        tiling_params->e_num_last_part_input_scalar;
    // last part last core
    tiling_params->input_mov_times_gm2ub_last_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar = ub_tensor_ele_num;
    tiling_params->input_last_ele_num_ub_last_part_last_core_input_scalar = tiling_params->e_num_last_part_input_scalar;

    // output init params
    tiling_params->input_last_axis_align_front_part_ele_num_input_scalar =
        tiling_params->e_num_last_part_input_scalar / FP32_ELE_NUM_ALIGN_32B * FP32_ELE_NUM_ALIGN_32B;
    tiling_params->input_last_axis_align_floor_ele_num_input_scalar =
        UssCeil(tiling_params->e_num_last_part_input_scalar, FP32_ELE_NUM_ALIGN_32B);
    tiling_params->last_part_vadd_mask_input_scalar = tiling_params->e_num_last_part_input_scalar -
        tiling_params->input_last_axis_align_front_part_ele_num_input_scalar;

    return;
}

void CalcTilingFloat4LastAxisModify(UnsortedSegmentSumTilingParamsFp32 *tiling_params)
{
    // last axis is one modify
    // e num params
    tiling_params->e_num_input_scalar = 1;
    tiling_params->e_mov_times_gm2ub_input_scalar = 1;
    tiling_params->e_ub2gm_front_burst_len_input_scalar = 1;

    // input data params
    // front part front core
    tiling_params->input_front_burst_len_front_part_front_core_input_scalar =
        tiling_params->ids_front_burst_len_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar;
    tiling_params->input_front_rows_front_part_front_core_input_scalar =
        tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar;
    // last part front core
    tiling_params->input_front_burst_len_last_part_front_core_input_scalar =
        tiling_params->ids_last_burst_len_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar;
    tiling_params->input_front_rows_last_part_front_core_input_scalar =
        tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar;
    // front part last core
    tiling_params->input_front_burst_len_front_part_last_core_input_scalar =
        tiling_params->ids_front_burst_len_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar;
    tiling_params->input_front_rows_front_part_last_core_input_scalar =
        tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar;
    // last part last core
    tiling_params->input_front_burst_len_last_part_last_core_input_scalar =
        tiling_params->ids_last_burst_len_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar;
    tiling_params->input_front_rows_last_part_last_core_input_scalar =
        tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar;

    // output init params
    tiling_params->output_ub_init_times_front_part_front_core_input_scalar =
        UssCeilDiv(tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar, MASK_FP32);
    tiling_params->output_ub_init_times_last_part_front_core_input_scalar =
        UssCeilDiv(tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar, MASK_FP32);
    tiling_params->output_ub_init_times_front_part_last_core_input_scalar =
        UssCeilDiv(tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar, MASK_FP32);
    tiling_params->output_ub_init_times_last_part_last_core_input_scalar =
        UssCeilDiv(tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar, MASK_FP32);
    tiling_params->last_part_vadd_mask_input_scalar = tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar -
        (tiling_params->output_ub_init_times_last_part_last_core_input_scalar - 1) * MASK_FP32;

    return;
}

void CalcTilingFloat4LastAxisOneMulti(UnsortedSegmentSumTilingParamsFp32 *tiling_params)
{
    // last axis is one multi 64

    // e num params
    tiling_params->e_num_input_scalar = 1;
    tiling_params->e_mov_times_gm2ub_input_scalar = 1;
    tiling_params->e_ub2gm_front_burst_len_input_scalar = 1;

    // input data params
    // front part front core
    tiling_params->input_front_burst_len_front_part_front_core_input_scalar =
        tiling_params->ids_front_burst_len_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar;
    tiling_params->input_front_rows_front_part_front_core_input_scalar =
        tiling_params->input_front_ele_num_ub_front_part_front_core_input_scalar;
    // last part front core
    tiling_params->input_front_burst_len_last_part_front_core_input_scalar =
        tiling_params->ids_last_burst_len_front_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar;
    tiling_params->input_front_rows_last_part_front_core_input_scalar =
        tiling_params->input_front_ele_num_ub_last_part_front_core_input_scalar;
    // front part last core
    tiling_params->input_front_burst_len_front_part_last_core_input_scalar =
        tiling_params->ids_front_burst_len_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar;
    tiling_params->input_front_rows_front_part_last_core_input_scalar =
        tiling_params->input_front_ele_num_ub_front_part_last_core_input_scalar;
    // last part last core
    tiling_params->input_front_burst_len_last_part_last_core_input_scalar =
        tiling_params->ids_last_burst_len_last_core_input_scalar;
    tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar;
    tiling_params->input_front_rows_last_part_last_core_input_scalar =
        tiling_params->input_front_ele_num_ub_last_part_last_core_input_scalar;

    // output init params
    // front part front core
    tiling_params->output_ub_init_times_front_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar / (MASK_FP32 * MULTI);
    tiling_params->output_ub_init_last_repeat_time_front_part_front_core_input_scalar =
        ComputeDivRemainders(tiling_params->ids_ele_num_ub_front_part_front_core_input_scalar, MASK_FP32 * MULTI,
        tiling_params->output_ub_init_times_front_part_front_core_input_scalar) /
        MASK_FP32;
    // last part front core
    tiling_params->output_ub_init_times_last_part_front_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar / (MASK_FP32 * MULTI);
    tiling_params->output_ub_init_last_repeat_time_last_part_front_core_input_scalar =
        ComputeDivRemainders(tiling_params->ids_ele_num_ub_last_part_front_core_input_scalar, MASK_FP32 * MULTI,
        tiling_params->output_ub_init_times_last_part_front_core_input_scalar) /
        MASK_FP32;
    // front part last core
    tiling_params->output_ub_init_times_front_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar / (MASK_FP32 * MULTI);
    tiling_params->output_ub_init_last_repeat_time_front_part_last_core_input_scalar =
        ComputeDivRemainders(tiling_params->ids_ele_num_ub_front_part_last_core_input_scalar, MASK_FP32 * MULTI,
        tiling_params->output_ub_init_times_front_part_last_core_input_scalar) /
        MASK_FP32;
    // last part last core
    // multi 64 part
    tiling_params->output_ub_init_times_last_part_last_core_input_scalar =
        tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar / (MASK_FP32 * MULTI);
    // single 64 part
    tiling_params->output_ub_init_last_repeat_time_last_part_last_core_input_scalar =
        ComputeDivRemainders(tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar, MASK_FP32 * MULTI,
        tiling_params->output_ub_init_times_last_part_last_core_input_scalar) /
        MASK_FP32;
    // last mask part
    tiling_params->last_part_vadd_mask_input_scalar =
        ComputeDivRemainders(tiling_params->ids_ele_num_ub_last_part_last_core_input_scalar, MASK_FP32 * MULTI,
        tiling_params->output_ub_init_times_last_part_last_core_input_scalar) -
        tiling_params->output_ub_init_last_repeat_time_last_part_last_core_input_scalar * MASK_FP32;

    return;
}

void CalcTilingFloat4NumSegmentOne(UnsortedSegmentSumTilingParamsFp32 *tiling_params, const EleByte input_ele_byte,
    const int32_t x_ub_size, const int32_t e_size, const int32_t ub_tensor_ele_num)
{
    tiling_params->e_mov_times_gm2ub_input_scalar = UssCeilDiv(e_size, ub_tensor_ele_num);
    tiling_params->e_ub2gm_front_burst_len_input_scalar = x_ub_size / BYTE_BLOCK;
    tiling_params->e_num_front_part_input_scalar = ub_tensor_ele_num;
    tiling_params->e_num_last_part_input_scalar = ComputeDivRemainders(e_size,
        tiling_params->e_num_front_part_input_scalar, tiling_params->e_mov_times_gm2ub_input_scalar - 1);
    tiling_params->e_ub2gm_last_burst_len_input_scalar =
        UssCeilDiv(tiling_params->e_num_last_part_input_scalar * input_ele_byte, BYTE_BLOCK);

    return;
}

ge::graphStatus CalcTiling4Float(gert::TilingContext *context, const int32_t e_size, const int32_t num_segments,
    const int32_t input_size, const int32_t ids_size, const int32_t output_ub_ele_num_one_row,
    const EleByte input_ele_byte, const EleByte ids_ele_byte)
{
    auto compile_info =
        reinterpret_cast<const TilingPrepareForUnsortedSegmentSumCompileInfo *>(context->GetCompileInfo());
    if (compile_info == nullptr) {
        HCCL_ERROR("compile_info is null");
        return ge::GRAPH_FAILED;
    }

    int32_t ids_ub_size = 0;
    int32_t x_ub_size = 0;
    int32_t x_ub_size_pad = 0;
    CommParas commParas = { 0 };
    commParas.e_num = e_size;
    commParas.x_e_num = input_size;
    commParas.num_segments = num_segments;
    commParas.ub_size = compile_info->ub_size;
    commParas.impl_mode = compile_info->impl_mode;

    ComputeUbTensorSize(commParas, x_ub_size, ids_ub_size, x_ub_size_pad);
    HCCL_DEBUG("x_ub_size_pad is %d", x_ub_size_pad);
    HCCL_DEBUG("ub_tensor_size=%d, %d", ids_ub_size, x_ub_size);
    CHK_PRT_RET(input_ele_byte == 0, HCCL_ERROR("CalcTiling4Float check failed input_ele_byte is 0."),
        ge::GRAPH_FAILED);
    int32_t ub_tensor_ele_num = x_ub_size / input_ele_byte;
    int32_t ub_tensor_ele_num_pad = x_ub_size_pad / input_ele_byte;
    commParas.ub_tensor_ele_num = ub_tensor_ele_num;
    commParas.ub_tensor_ele_num_pad = ub_tensor_ele_num_pad;
    commParas.e_size_align = UssCeil(e_size, FP32_ELE_NUM_ALIGN_32B);
    // fp32 tiling params
    auto tiling_params = context->GetTilingData<UnsortedSegmentSumTilingParamsFp32>();
    if (tiling_params == nullptr) {
        HCCL_ERROR("tiling_params is null");
        return ge::GRAPH_FAILED;
    }
    InitTilingParams(tiling_params, num_segments);
    tiling_params->tiling_core_num = compile_info->core_num;
    HCCL_DEBUG("CalcTiling4Float set tiling core num: %d", tiling_params->tiling_core_num);

    // select key
    CHK_PRT_RET(!GetTilingMode(commParas, x_ub_size, tiling_params->select_key_input_scalar),
        HCCL_ERROR("GetTilingMode failed."), ge::GRAPH_FAILED);
    tiling_params->e_num_input_scalar = e_size;
    tiling_params->input_last_axis_align_floor_ele_num_input_scalar = commParas.e_size_align;
    tiling_params->e_num_sub = commParas.e_size_align - e_size;
    tiling_params->move_pad = e_size * input_ele_byte;
    tiling_params->max_cache_n_num = ub_tensor_ele_num_pad / commParas.e_size_align;
    if (tiling_params->max_cache_n_num > num_segments) {
        tiling_params->max_cache_n_num = num_segments;
    }
    tiling_params->repeat_remove_pad = tiling_params->max_cache_n_num / PAD_ONCE;
    int32_t remain = ComputeDivRemainders(tiling_params->max_cache_n_num, PAD_ONCE, tiling_params->repeat_remove_pad);
    tiling_params->col_block_remove_pad = UssCeilDiv(remain * commParas.e_size_align, INT32_BLOCK_NUM);
    tiling_params->cache_num_block = UssCeilDiv(tiling_params->max_cache_n_num * e_size, INT32_BLOCK_NUM);
    HCCL_DEBUG("e_size_align is %d, e_num_sub is %d, max_cache_n_num is %d", commParas.e_size_align,
        tiling_params->e_num_sub, tiling_params->max_cache_n_num);

    // ids params compute is common
    tiling_params->ids_size_input_scalar = ids_size;
    CHK_PRT_RET(ids_ele_byte == 0, HCCL_ERROR("CalcTiling4Float check failed ids_ele_byte is 0."), ge::GRAPH_FAILED);
    int32_t ids_min_ele_num = BYTE_BLOCK / ids_ele_byte;

    // calc need core num
    CHK_PRT_RET(CalcNeededCoreNum(context, commParas, ids_size, compile_info->core_num,
        tiling_params->need_core_num_input_scalar),
        HCCL_ERROR("CalcNeededCoreNum failed."), ge::GRAPH_FAILED);
    ComputeEleNumOneCore(ids_min_ele_num, ids_size, e_size, num_segments, tiling_params);

    // ids params front core
    uint32_t mode = FRONT_CORE;
    ComputeIdsParamsMovGm2ub(ids_ub_size, ids_ele_byte, mode, tiling_params);

    // ids params last core
    mode = LAST_CORE;
    ComputeIdsParamsMovGm2ub(ids_ub_size, ids_ele_byte, mode, tiling_params);

    if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_SMALL_E ||
        tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_SMALL_E_HP) {
        CalcTilingFloat4LastAxisSmallE(tiling_params, commParas, x_ub_size, input_ele_byte, e_size);
    } else if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ONE) {
        CalcTilingFloat4LastAxisOne(tiling_params, output_ub_ele_num_one_row);
    } else if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E ||
        tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E_HP ||
        tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_SMALL_E_HP_PAD) {
        CalcTilingFloat4LastAxisNotAlignSmallE(tiling_params, x_ub_size, input_ele_byte, commParas,
            output_ub_ele_num_one_row);
    } else if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ALIGN_BIG_E) {
        CalcTilingFloat4LastAxisAlignBigE(x_ub_size, input_ele_byte, e_size, ub_tensor_ele_num, tiling_params);
    } else if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_NOT_ALIGN_BIG_E) {
        CalcTilingFloat4LastAxisNotAlignBigE(tiling_params, x_ub_size, input_ele_byte, e_size, ub_tensor_ele_num);
    } else if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ONE_MODIFY) {
        CalcTilingFloat4LastAxisModify(tiling_params);
    } else if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_LAST_AXIS_ONE_MULTI) {
        CalcTilingFloat4LastAxisOneMulti(tiling_params);
    } else if (tiling_params->select_key_input_scalar == SELECT_KEY_MODE_FP32_INPUT_NUM_SEGMENT_ONE) {
        CalcTilingFloat4NumSegmentOne(tiling_params, input_ele_byte, x_ub_size, e_size, ub_tensor_ele_num);
    }

    // cout tiling params
    PrintTilingParams(context, tiling_params);
    // BlockDim, core num used in tik op
    context->SetBlockDim(tiling_params->need_core_num_input_scalar);

    return ge::GRAPH_SUCCESS;
}

ge::graphStatus CalcTiling4Int(gert::TilingContext *context, const ge::DataType input_dtype,
    const ge::DataType ids_dtype, const int32_t output_ub_ele_num_one_row, const int32_t num_segments,
    const int32_t e_size, const int32_t input_size, const int32_t ids_size, const EleByte input_ele_byte,
    const EleByte ids_ele_byte)
{
    auto compile_info =
        reinterpret_cast<const TilingPrepareForUnsortedSegmentSumCompileInfo *>(context->GetCompileInfo());
    if (compile_info == nullptr) {
        HCCL_ERROR("compile_info is null");
        return ge::GRAPH_FAILED;
    }

    // int32 tiling params
    auto tiling_params = context->GetTilingData<UnsortedSegmentSumTilingParamsInt32>();
    if (tiling_params == nullptr) {
        HCCL_ERROR("tiling_params is null");
        return ge::GRAPH_FAILED;
    }
    InitTilingParams(tiling_params, num_segments);
    tiling_params->tiling_core_num = compile_info->core_num;
    HCCL_DEBUG("CalcTiling4Int set tiling core num: %d", tiling_params->tiling_core_num);

    // commmn params
    // select key
    int32_t e_once_num = 0;
    int32_t id_once_num = 0;
    int32_t mask = 0;
    mask = (input_dtype == ge::DT_INT32) ? MASK_INT32 : MASK_FP16;

    CommParas4UbSizeNoAtomic comm_ub_size_params;
    comm_ub_size_params.ub_size = compile_info->ub_size;
    comm_ub_size_params.input_dtype = input_dtype;
    comm_ub_size_params.e_size = e_size;
    comm_ub_size_params.output_ub_ele_num_one_row = output_ub_ele_num_one_row;
    comm_ub_size_params.mask = mask;
    comm_ub_size_params.num_segments = num_segments;

    CHK_PRT_RET(CalcNeededCoreByNumSegments(context, comm_ub_size_params, compile_info->core_num,
        tiling_params->need_core_num_input_scalar),
        HCCL_ERROR("CalcNeededCoreByNumSegments failed."), ge::GRAPH_FAILED);
    comm_ub_size_params.need_core_num = tiling_params->need_core_num_input_scalar;

    int32_t ub_tensor_size = 0;
    int32_t ub_tensor_size_input = 0;
    int32_t ub_tensor_size_output = 0;

    ComputeUbTensorSizeNoAtomic(comm_ub_size_params, ub_tensor_size, ub_tensor_size_input, ub_tensor_size_output);
    HCCL_DEBUG("ub_tensor_size_id is=%d, ub_tensor_size_input is %d, ub_tensor_size_output is %d", ub_tensor_size,
        ub_tensor_size_input, ub_tensor_size_output);

    CommParas4TilingModeNoAtomic comm_tiling_mode_params;
    comm_tiling_mode_params.e_size = e_size;
    comm_tiling_mode_params.ids_size = ids_size;
    comm_tiling_mode_params.input_dtype = input_dtype;
    comm_tiling_mode_params.ub_tensor_size = ub_tensor_size;
    comm_tiling_mode_params.ub_tensor_size_input = ub_tensor_size_input;
    comm_tiling_mode_params.need_core = tiling_params->need_core_num_input_scalar;
    comm_tiling_mode_params.output_ub_ele_num_one_row = output_ub_ele_num_one_row;
    comm_tiling_mode_params.all_size = input_size;
    comm_tiling_mode_params.num_segments = num_segments;
    CHK_PRT_RET(!GetTilingModeNoAtomic(comm_tiling_mode_params, tiling_params->select_key_input_scalar, e_once_num,
        id_once_num, tiling_params->num_segment_max),
        HCCL_ERROR("GetTilingModeNoAtomic failed."), ge::GRAPH_FAILED);
    ComputeNumSegmentsParams(num_segments, e_size, output_ub_ele_num_one_row, tiling_params);

    // ids params
    tiling_params->ids_size_input_scalar = ids_size;
    ComputeIdsParamsMovGm2ubNoAtomic(ids_size, id_once_num, ids_ele_byte, tiling_params);

    // e num params
    tiling_params->e_num_input_scalar = e_size;

    CommParas4Int32 comm_paras;
    comm_paras.input_dytpe = input_dtype;
    comm_paras.ele_byte = input_ele_byte;
    comm_paras.e_once_num = e_once_num;
    comm_paras.all_size = input_size;
    comm_paras.num_segments = num_segments;
    ComputeENumParams(comm_paras, tiling_params);

    // cout tiling params
    PrintTilingParams(context, tiling_params);
    // BlockDim, core num used in tik op
    context->SetBlockDim(tiling_params->need_core_num_input_scalar);

    return ge::GRAPH_SUCCESS;
}

inline bool IsConstTensor(const gert::Tensor *input_tensor)
{
    if (input_tensor != nullptr) {
        if (input_tensor->GetAddr() == nullptr) {
            // empty tensor
            return input_tensor->GetShapeSize() == 0;
        }
        return true;
    }
    return false;
}

template <typename T> bool GetConstInt(gert::TilingContext *context, const int64_t const_input_idx, T &value)
{
    const gert::Tensor *const_tensor = context->GetInputTensor(const_input_idx);
    if (const_tensor == nullptr) {
        HCCL_ERROR("const_tensor is null");
        return false;
    }
    if (!IsConstTensor(const_tensor)) {
        HCCL_ERROR("the input is not const tensor, will return failed.");
        return false;
    }

    ge::DataType dtype = const_tensor->GetDataType();
    switch (dtype) {
        case ge::DT_UINT64:
            value = static_cast<T>(const_tensor->GetData<uint64_t>()[0]);
            break;
        case ge::DT_INT64:
            value = static_cast<T>(const_tensor->GetData<int64_t>()[0]);
            break;
        case ge::DT_UINT32:
            value = static_cast<T>(const_tensor->GetData<uint32_t>()[0]);
            break;
        case ge::DT_INT32:
            value = static_cast<T>(const_tensor->GetData<int32_t>()[0]);
            break;
        default:
            return false;
    }
    HCCL_INFO("GetConstInt, GetConstInt of value is %d", value);
    return true;
}

ge::graphStatus SegmentDSLTiling(gert::TilingContext *context,
    const TilingPrepareForUnsortedSegmentSumCompileInfo *compile_info)
{
    HCCL_DEBUG("SegmentDSLTiling running");
    if (compile_info->dsl_compile_info == nullptr) {
        HCCL_ERROR("dsl_compile_info is null");
        return ge::GRAPH_FAILED;
    }
    TbeReduce::OpInfo segment_info(compile_info->dsl_compile_info.get());
    CHK_SMART_PTR_NULL(segment_info);
    CHK_PRT_RET(!TbeReduce::DoAutoTiling(context, &segment_info), HCCL_ERROR("call DoAutoTiling failed"),
        ge::GRAPH_FAILED);
    HCCL_DEBUG("SegmentDSLTiling end.");
    return ge::GRAPH_SUCCESS;
}

// tiling function
ge::graphStatus Tiling4UnsortedSegmentSum(gert::TilingContext *context)
{
    HCCL_INFO("Tiling4UnsortedSegmentSum is running.");
    auto compile_info =
        reinterpret_cast<const TilingPrepareForUnsortedSegmentSumCompileInfo *>(context->GetCompileInfo());
    if (compile_info == nullptr) {
        HCCL_ERROR("compile_info is null");
        return ge::GRAPH_FAILED;
    }

    CHK_PRT_RET(SegmentDSLTiling(context, compile_info) != ge::GRAPH_SUCCESS, HCCL_ERROR("call TIKTiling failed"),
        ge::GRAPH_FAILED);

    HCCL_DEBUG("Tiling4UnsortedSegmentSum is end");
    return ge::GRAPH_SUCCESS;
}

template <typename T> void GetValueToShape(const gert::Tensor *const_tensor, gert::Shape *const_shape)
{
    const T *const_value = const_tensor->GetData<T>();
    const size_t const_num = const_tensor->GetShapeSize();
    const_shape->SetDimNum(0);
    for (size_t i = 0; i < const_num; ++i) {
        const_shape->AppendDim(const_value[i]);
    }
}

template <typename T> void GetValueToShape(const gert::Tensor *const_tensor, gert::Shape &const_shape)
{
    const T *const_value = const_tensor->GetData<T>();
    const size_t const_num = const_tensor->GetShapeSize();
    const_shape.SetDimNum(0);
    for (size_t i = 0; i < const_num; ++i) {
        const_shape.AppendDim(const_value[i]);
    }
}

template <typename T> bool GetConstIntToShape(T *context, const int64_t const_idx, gert::Shape &const_shape)
{
    const gert::Tensor *const_tensor = context->GetInputTensor(const_idx);
    if (const_tensor == nullptr) {
        HCCL_ERROR("const_tensor is null");
        return false;
    }
    if (!IsConstTensor(const_tensor)) {
        HCCL_WARNING("the input[%ld] is not const tensor, will return failed.", const_idx);
        return false;
    }

    ge::DataType const_dtype = const_tensor->GetDataType();

    switch (const_dtype) {
        case ge::DT_INT32: {
            optilingUss::GetValueToShape<int32_t>(const_tensor, const_shape);
            break;
        }
        case ge::DT_INT64: {
            optilingUss::GetValueToShape<int64_t>(const_tensor, const_shape);
            break;
        }
        case ge::DT_UINT64: {
            optilingUss::GetValueToShape<uint64_t>(const_tensor, const_shape);
            break;
        }
        case ge::DT_UINT32: {
            optilingUss::GetValueToShape<uint32_t>(const_tensor, const_shape);
            break;
        }
        default:
            HCCL_WARNING(
                "optilingGather::optilingGather::GetConstIntToShape only support [int32, int64, uint64, uint32]. ");
            return false;
    }
    return true;
}

bool GetTilingCoreNum(gert::TilingParseContext *context, uint32_t &core_num)
{
    auto platform_info = context->GetPlatformInfo();
    if (platform_info == nullptr) {
        HCCL_ERROR("platform_info is null");
        return false;
    }
    core_num = context->GetPlatformInfo()->GetCoreNum();
    HCCL_DEBUG("get tiling core num is %u", core_num);
    return true;
}

ge::graphStatus TilingPrepare4SegmentSumComm(gert::TilingParseContext *context)
{
    HCCL_DEBUG("begin to do TilingPrepare4SegmentSumComm.");
    auto compile_info = TbeReduce::GetCompileInfoPtr<TilingPrepareForUnsortedSegmentSumCompileInfo>(context);
    if (compile_info == nullptr) {
        HCCL_ERROR("compile_info is null");
        return ge::GRAPH_FAILED;
    }

    std::unique_ptr<nlohmann::json> parsed_object_cinfo = TbeReduce::GetCompileInfoJson(context);
    if (parsed_object_cinfo == nullptr) {
        HCCL_ERROR("parsed_object_cinfo is null");
        return ge::GRAPH_FAILED;
    }

    if (ReadCompileItem(*parsed_object_cinfo, "is_tik", compile_info->is_tik)) {
        const nlohmann::json &all_vars = (*parsed_object_cinfo)["vars"];
        uint32_t core_num = 0;
        CHK_PRT_RET(!GetTilingCoreNum(context, core_num), HCCL_ERROR("get tiling core num failed."), ge::GRAPH_FAILED);
        compile_info->core_num = static_cast<int32_t>(core_num);
        CHK_PRT_RET(compile_info->core_num < 1, HCCL_ERROR("core_num should be greater than 0"), ge::GRAPH_FAILED);
        CHK_PRT_RET(!ReadCompileItem(all_vars, "ub_size", compile_info->ub_size),
            HCCL_ERROR("get ub_size from compile info faided."), ge::GRAPH_FAILED);
        CHK_PRT_RET(!ReadCompileItem(all_vars, "ub_tensor_num", compile_info->ub_tensor_num),
            HCCL_ERROR("get ub_tensor_num from compile info faided."), ge::GRAPH_FAILED);
        CHK_PRT_RET(!ReadCompileItem(all_vars, "impl_mode", compile_info->impl_mode),
            HCCL_ERROR("get impl_mode from compile info faided."), ge::GRAPH_FAILED);
        HCCL_DEBUG("compile_info: core_num is %d, ub_size is %d, ub_tensor_num is %d, impl_mode is %d",
            compile_info->core_num, compile_info->ub_size, compile_info->ub_tensor_num, compile_info->impl_mode);
    } else {
        HCCL_DEBUG("will use segment AotoTiling");
        compile_info->dsl_compile_info = TbeReduce::ParseAutoTiling(context, *parsed_object_cinfo);
        CHK_PRT_RET(compile_info->dsl_compile_info == nullptr, HCCL_ERROR("CreateSegmentTilingHandler failed"),
            ge::GRAPH_FAILED);
        compile_info->is_tik = false;
    }
    HCCL_DEBUG("TilingPrepare4SegmentSumComm is end");
    return ge::GRAPH_SUCCESS;
}

} // namespace optilingUss
